, ग्राहक वर्ग का उपयोग करना WCF आप द्वैध नामित पाइप का उपयोग कर सकते
// Create a contract that can be used as a callback
public interface IMyCallbackService
{
[OperationContract(IsOneWay = true)]
void NotifyClient();
}
// Define your service contract and specify the callback contract
[ServiceContract(CallbackContract = typeof(IMyCallbackService))]
public interface ISimpleService
{
[OperationContract]
string ProcessData();
}
सेवा को लागू
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
public class SimpleService : ISimpleService
{
public string ProcessData()
{
// Get a handle to the call back channel
var callback = OperationContext.Current.GetCallbackChannel<IMyCallbackService>();
callback.NotifyClient();
return DateTime.Now.ToString();
}
}
होस्ट सेवा
class Server
{
static void Main(string[] args)
{
// Create a service host with an named pipe endpoint
using (var host = new ServiceHost(typeof(SimpleService), new Uri("net.pipe://localhost")))
{
host.AddServiceEndpoint(typeof(ISimpleService), new NetNamedPipeBinding(), "SimpleService");
host.Open();
Console.WriteLine("Simple Service Running...");
Console.ReadLine();
host.Close();
}
}
}
क्लाइंट अनुप्रयोग बनाएँ इस उदाहरण में कॉल बैक कॉन्ट्रैक्ट लागू करता है।
class Client : IMyCallbackService
{
static void Main(string[] args)
{
new Client().Run();
}
public void Run()
{
// Consume the service
var factory = new DuplexChannelFactory<ISimpleService>(new InstanceContext(this), new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/SimpleService"));
var proxy = factory.CreateChannel();
Console.WriteLine(proxy.ProcessData());
}
public void NotifyClient()
{
Console.WriteLine("Notification from Server");
}
}
स्रोत
2013-05-08 05:20:41
आप इस्तेमाल कर सकते हैं WCF डुप्लेक्स NamedPipes, मैं अपने सेवा/अनुप्रयोग संचार, यहाँ एक अच्छा उदाहरण help.http सकता है के लिए इस विधि का उपयोग: //tech.pro/tutorial/855/wcf-tutorial- बुनियादी-इंटरप्रोसेस-संचार –