Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a barebone example with a self hosted service and client.</p> <p><strong>Contracts</strong></p> <pre><code>[ServiceContract(CallbackContract = typeof(IService1Callback), SessionMode=SessionMode.Required)] public interface IService1 { [OperationContract] void Process(string what); } public interface IService1Callback { [OperationContract] void Progress(string what, decimal percentDone); } </code></pre> <p><strong>Server</strong></p> <pre><code>[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] public class Service1 : IService1 { public void Process(string what) { Console.WriteLine("I'm processing {0}", what); for (int i = 0; i &lt; 10; i++) { OperationContext.Current.GetCallbackChannel&lt;IService1Callback&gt;().Progress(what, (i+1)*0.1M); } } } class Program { static void Main(string[] args) { using (ServiceHost host = new ServiceHost( typeof(Service1), new Uri[] { new Uri("net.tcp://localhost:6789") })) { host.AddServiceEndpoint(typeof(IService1), new NetTcpBinding(SecurityMode.None), "Service1"); host.Open(); Console.ReadLine(); host.Close(); } } } </code></pre> <p><strong>Client</strong></p> <pre><code>public class CallbackHandler : IService1Callback { public void Progress(string what, decimal percentDone) { Console.WriteLine("Have done {0:0%} of {1}", percentDone, what); } } class Program { static void Main(string[] args) { // Setup the client var callbacks = new CallbackHandler(); var endpoint = new EndpointAddress(new Uri("net.tcp://localhost:6789/Service1")); using (var factory = new DuplexChannelFactory&lt;IService1&gt;(callbacks, new NetTcpBinding(SecurityMode.None), endpoint)) { var client = factory.CreateChannel(); client.Process("JOB1"); Console.ReadLine(); factory.Close(); } } } </code></pre> <p>This uses a duplex channel over net.tcp with communications being triggered by the server to inform the client of progress updates.</p> <p>The client will display:</p> <pre><code>Have done 10% of JOB1 Have done 20% of JOB1 Have done 30% of JOB1 Have done 40% of JOB1 Have done 50% of JOB1 Have done 60% of JOB1 Have done 70% of JOB1 Have done 80% of JOB1 Have done 90% of JOB1 Have done 100% of JOB1 </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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