I am starting to develop the following scenario (Visual Studio 2010, WCF): Different clients in our network will call a web service that I developed myself, which is hosted as part of a windows service, so we are talking about a self hosted WCF Web Service inside a Windows Service.
That self hosted WCF Web Service will in turn make calls to an external Web Service, so is acting like a sort of facade.
Obviously my self hosted WCF Web Service will need to accept concurrent calls and here comes my question: What I am planning to is in the operations that are called from the different clients on my self hosted WCF Web Service, I would simply create the client for the external webservice, make the call to the external webservice, get a syncronous response back from the external web service and then reply to the calling client.
Sounds simple, but is there anything I need to consider about multiple threads entering my service host? Obviously I need to be careful with any "global" variables in the host itself, but I should be save if I simply create the external web service clients in the different operations of the called web service, or have I overlooked something?
Thanks all!
Cheers, Stevo
You have a few choices here, particularly as they relate to WCF instancing and Concurrency.
Instancing: Your choices here are
Concurrency:
Lets look at Instancing first:
Per Call: Basically here what happens is if two clients make a call to your service, 2 different instances of your service are created, and then destroyed once the call is complete
Per Session: If those two clients make 2 calls each via your proxy, the wcf instance created on your host for both of those calls will be the same (for each proxy so 2 instances serving 2 each but each caller goes to the same instance), and then destroyed
Single: Both proxies/clients will use the same instance, so caller 1 invokes an operation, and then caller 2 makes a call, this same instance will be reused.
Pretty straight forward.
As far as concurrency goes, its the number of threads active in the above mentioned instance context at one time. Here i side with experience and MSDN, which states that "understanding and developing code that safely uses more than one thread can be difficult to write" (but not impossible)
So based on your requirements it seems you don't want to maintain state and scalability could be concern since you are servicing multiple proxy calls and you don't need to share any kind of global data that would necessitate Single Instance mode, then the most likely solution would be:
[ServiceBehavior
(ConcurrencyMode.Single,
InstanceContextMode=InstanceContextMode.PerCall)]
public class YourService: IYourService
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With