Link to home
Start Free TrialLog in
Avatar of SanjaySutar
SanjaySutarFlag for India

asked on

WCF InvalidOperationException in service

Hi,

My WCF service is throwing exception as follows:

This operation would deadlock because the reply cannot be received until the current Message completes processing. If you want to allow out-of-order message processing, specify ConcurrencyMode of Reentrant or Multiple on CallbackBehaviorAttribute.

Service Code is as follows :

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
    public class CalculatorService : IWebMxAccessServerService
    {
public int Register(string tag)
        {
            int tagHandle = 0;
            try
            {
                tagHandle = wmxServer.Advise(param1,param2);
                return tagHandle;
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("WCF Service", ex.Message + Environment.NewLine + ex.StackTrace);
                throw;
            }
        }
}

Open in new window



[ServiceContract(Namespace = "", SessionMode = SessionMode.Required,
    CallbackContract = typeof(IWebMxAccessServerServiceCallback))]
    public interface IWebMxAccessServerService
    {
[OperationContract]
int Register(string tag);
}

Open in new window



 
public interface IWebMxAccessServerServiceCallback
    {

        [OperationContract(IsOneWay = true)]
        void ReceiveMxData(TagUpdatedEventArgs tagDetails);

    }

Open in new window



WCF Consumer UI class

Implementing CallBack on client side
[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Single)]
    public class WebMxAccess : IWebMxAccessServerServiceCallback
    {
       
}

I am getting above mentioned error when i am calling Register operation contract of service.

Any help would be appreciated.
Avatar of Darren
Darren
Flag of Ireland image

Hi,

On the Service add ConcurrencyMode=ConcurrencyMode.Reentrant to the attributes.

Hope this helps,

Darren

Avatar of SanjaySutar

ASKER

Hi Darren, I have added the attribute, but now started getting different error.

Please find below the stack trace :

Message: The message could not be transferred within the allotted timeout of 00:01:00. There was no space available in the reliable channel's transfer window. The time allotted to this operation may have been a portion of a longer timeout.
Source: mscorlib
Stack Trace: 
Server stack trace: 
   at System.ServiceModel.Channels.TransmissionStrategy.WaitQueueAdder.Wait(TimeSpan timeout)
   at System.ServiceModel.Channels.TransmissionStrategy.InternalAdd(Message message, Boolean isLast, TimeSpan timeout, Object state, MessageAttemptInfo& attemptInfo)
   at System.ServiceModel.Channels.ReliableOutputConnection.InternalAddMessage(Message message, TimeSpan timeout, Object state, Boolean isLast)
   at System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnSend(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.DuplexChannel.Send(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.DuplexChannelBinder.Send(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Darren
Darren
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Darren, thanks for the example.

I have fixed the problem of Timout.

Along with the attribute mentioned by you earlier, I have added UseSynchronizationContext = false and it started working.


[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, UseSynchronizationContext = false)]

Open in new window



Thanks again.