Note that there are some explanatory texts on larger screens.

plurals
  1. POInstantiate WCF service object on server, not client?
    text
    copied!<p>I am writing two applications in C# that need to be able to communicate (in one direction only). The two apps will always run on the same machine, so using WCF with named pipes, and self-hosting the WCF service, seemed like the logical choice.</p> <p>I understand that I can use <strong>InstanceContextMode</strong> to configure if a service instance is instantiated per session, per call, or if there should just be a single instance. In my case I want a single instance, because I will have just the two apps running, so there will be a single client and a single server. </p> <p>But here's where I'm stuck. When my client makes a call on the service, which I'm doing this way:</p> <pre><code>var myServiceFactory = new ChannelFactory&lt;IMyService&gt;( new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/MyService")); IMyService myService = myServiceFactory.CreateChannel(); myService.DoStuff(); </code></pre> <p>I don't want a new server object instance to be created on the server. Instead I'd like <em>myService</em> to point at the (one and only) IMyService instance that has <strong>already been constructed</strong> on the server. At the moment, a second IMyService instance gets constructed.</p> <p>In other words, I want my server object to be constructed by the server (when the server starts up), not when a client first makes a call.</p> <p>Can anyone explain how to do this? From what I understand, .NET Remoting makes this quite easy, and WCF has supposedly replaced Remoting, so there must be an easy way... right?</p>
 

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