Pablo
Pablo

Reputation: 29519

Can WCF handle simultaneous calls to the same endpoint?

I am developing WCF application under Windows Service which is exposing one endpoint. There can be about 40 remote clients who will connect to this endpoint over local area network at the same time. My question is whether WCF can handle multiple calls to the same endpoint by queuing them? No request from any client can be lost. Is there anything special I have to consider when developing application to handle simultaneous calls?

Upvotes: 4

Views: 3800

Answers (2)

Jan Köhler
Jan Köhler

Reputation: 6030

You can choose whether the requests should be handled asynchronously or synchronously one after another.

You can set this behavior via the InstanceContextMode settings. By default WCF handles requests ByCall which means one instance of your service will be created for each incoming request. This allows you to handle multiple requests in parallel.

Alternatively you can configure your service to spin off only one instance which ensures each request is handled after the other. This effectively is the "queuing" you mentioned. You can set this behavior via InstanceContextMode.Single. By chosing this mode, your service becomes a singleton. So this mode ensures there's only one instance of your service, which may come in handy in some cases. The framework handles the queuing.

Additionally you could set ConcurrencyMode.Multiple which allows your single instance to process multiple requests in parallel (see Andrew's comment).

However, be aware that the queued requests aren't persisted in any way. So if your service gets restarted, the not yet finished requests are lost.

I'd definitely recommend to avoid any kind of singleton if possible. Is there anything that prevents you from chosing the parallel PerCall-mode?

For more details have a look at this: http://www.codeproject.com/Articles/86007/ways-to-do-WCF-instance-management-Per-call-Per

Upvotes: 2

Ivan Stoev
Ivan Stoev

Reputation: 205629

Here are some useful links:

https://msdn.microsoft.com/en-us/library/ms752260(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/hh556230(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute(v=vs.110).aspx

To answer your question, no calls will be lost whatever you choose. But if you need to process them in order, you probably should use this setup for your service

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, EnsureOrderedDispatch = true )]

Upvotes: 2

Related Questions