Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed server to call client function ( NO CALLBACK!)
    primarykey
    data
    text
    <p>I've been doing some research on this and I got nothing. I have a server and client.</p> <p>My client does request to the server and the server runs some callbacks. This works fine. But now, there are some functions from the clients I need to call from the server and are not a result of a client call so I can't use callbacks there. I'm using WCF and .net 4.0</p> <p>Any suggestions?</p> <p>CLIENT:</p> <pre><code>using System; using System.ServiceModel; using System.ServiceModel.Channels; using System.Runtime.Serialization; using System.IO; using System.Collections; namespace WCFClient { [ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(ICallbacks))] public interface IMessageHandler { [OperationContract] void HandleMessage(); } public interface ICallbacks { [OperationContract(IsOneWay = true)] void QueuePaths_Callback(string cPath, string EPath, string RPath, string IPath, string OPath); } public class Callbacks : ICallbacks { public void QueuePaths_Callback(string cPath) { Console.WriteLine("QueuePaths_Callback: " + cPath); } } class Program { static void Main(string[] args) { Callbacks myCallbacks = new Callbacks(); DuplexChannelFactory&lt;IMessageHandler&gt; pipeFactory = new DuplexChannelFactory&lt;IMessageHandler&gt;( myCallbacks, new NetNamedPipeBinding(), new EndpointAddress( "net.pipe://localhost/PipeReverse")); IMessageHandler pipeProxy = pipeFactory.CreateChannel(); while (true) { string str = Console.ReadLine(); pipeProxy.HandleMessage();//send the type for example } } public void IWANTTOCALLTHISFROMSERVER() { } } } </code></pre> <p>SERVER:</p> <pre><code>namespace WCFServer { [ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(ICallbacks))] public interface IMessageHandler { [OperationContract] void HandleMessage(); } public interface ICallbacks { [OperationContract(IsOneWay = true)] void QueuePaths_Callback(string cPath); } public class StringReverser : IMessageHandler { public void HandleMessage()//handle the type and do the request { ICallbacks callbacks = OperationContext.Current.GetCallbackChannel&lt;ICallbacks&gt;(); callbacks.QueuePaths_Callback("path1"); } } class Program { static void Main(string[] args) { using (ServiceHost host = new ServiceHost( typeof(StringReverser), new Uri[]{ new Uri("net.pipe://localhost") })) { host.AddServiceEndpoint(typeof(IMessageHandler), new NetNamedPipeBinding(), "PipeReverse"); host. host.Open(); Console.WriteLine("Service is available. " + "Press &lt;ENTER&gt; to exit."); Console.ReadLine(); //BLA BLA BLA //CALL IWANTTOCALLTHISFROMSERVER(); host.Close(); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload