How to make WCF Service take only one call at a time

1.8k views Asked by At

We have a WCF service like

Public Class MyService

{

 [OperationContract]
 Public void OpperationA()
  {
  }

 [OperationContract]
 Public void OpperationB()
 {
  }

 [OperationContract]
 Public void OpperationC()
 {
  }

 [OperationContract]
 Public void OpperationD()
 {
  }
}

We have a client for this WCF service which is a windows service which invokes all the operations above OperationA/B/C/D with new proxies.

With the current implementation we have there are issues with Client Invoking all operations at the same time.
InstanceContextMode = PerCall and ConcurrencyMode = Single

Is there any combination of InstanceContextMode and COncurrency which Can change my service to take only one request at a time, I mean if client proxy A has called OPerationA and the service is processing the request and if the Client proxy B tries to call OperationB (or any other operation), it should be blocked until the first request is finished.

Thanks

2

There are 2 answers

2
Simon Taylor On

From http://msdn.microsoft.com/en-us/library/system.servicemodel.instancecontextmode%28v=vs.110%29.aspx

If the InstanceContextMode value is set to Single the result is that your service can only process one message at a time unless you also set the ConcurrencyMode value to Multiple.

Obviously that won't work if you have multiple service hosts.

0
Daniel Persson On

It should be sufficient to change the InstanceContextMode to Single. From the MSDN documentation here:

ConcurrencyMode=Single : The service instance is single-threaded and does not accept reentrant calls. If the InstanceContextMode property is Single, and additional messages arrive while the instance services a call, these messages must wait until the service is available or until the messages time out.