none
NetMessagingBinding and Concurrency RRS feed

  • Question

  • Currently we have a WCF Service with a NetMessagingBinding endpoint that seems to be processing the same message more than once. We are 100% sure that we are not pushing the same message twice or more times.

    The service is set up as follows:

    public class Service : IService
    {
            public void Push(MyType x)
            {
                var incomingProperties = OperationContext.Current.IncomingMessageProperties;
    
                ReceiveContext receiveContext;
                if (ReceiveContext.TryGet(incomingProperties, out receiveContext))
                {
                    try
                    {
                        AddToDb(x);
    
                        receiveContext.Complete(TimeSpan.FromSeconds(ReceiveContextOperationTimeout));
    
                    }
                    catch (Exception ex)
                    {
                        receiveContext.Abandon(ex, TimeSpan.FromSeconds(ReceiveContextOperationTimeout));
                    }
                }
                else
                {
                    string message = string.Format(NoReceiveContextMessage, "blah");
    
                    _logger.ErrorFormat(message);
                    throw new InvalidOperationException(message);
                }
            }
    }

    We are using the default concurrency modes. From MSDN they are InstanceContextMode.PerSession and ConcurrencyMode.Single. 

    If we set ConcurrencyMode.Single and InstanceContextMode.Single then the WCF Service doesn't process messages more than once.

    Is there something that we can fix in the code?

    Thanks in advance!

    Monday, July 1, 2013 2:02 PM

All replies

  • Hi,

    When sets the ServiceBehavior.InstanceContextMode property to InstanceContextMode.PerSession and the ConcurrencyMode property toConcurrencyMode.Single. This way the ServiceHost creates a new service instance every time a new session is available in the specified queue or subscription, and the ServiceHost uses a single thread to receive messages sequentially from the queue or subscription.

    [ServiceContract]
    public interface IService
    {
        [OperationContract(IsOneWay = true)]
        [ReceiveContextEnabled(ManualControl = true)]
        void Push(MyType x);
    }
    
    
    
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single)]
    public class Service : IService
    {
       
         public void Push(MyType x)
            {
                var incomingProperties = OperationContext.Current.IncomingMessageProperties;
    
                ReceiveContext receiveContext;
                if (ReceiveContext.TryGet(incomingProperties, out receiveContext))
                {
                    try
                    {
                        AddToDb(x);
    
                        receiveContext.Complete(TimeSpan.FromSeconds(ReceiveContextOperationTimeout));
    
                    }
                    catch (Exception ex)
                    {
                        receiveContext.Abandon(ex, TimeSpan.FromSeconds(ReceiveContextOperationTimeout));
                    }
                }
                else
                {
                    string message = string.Format(NoReceiveContextMessage, "blah");
    
                    _logger.ErrorFormat(message);
                    throw new InvalidOperationException(message);
                }
            }
    }

    For more information, please try to refer to:
    http://msdn.microsoft.com/zh-cn/library/windowsazure/hh532034.aspx .

    Hope it can help you.

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Tuesday, July 2, 2013 6:13 AM
    Moderator
  • Hi Amy. Thanks for your reply.

    Unfortunately, we already played around the InstanceContextMode and the ConcurrencyMode.

    As said previously the only mode were the problem did not appear was when InstanceContextMode and ConcurrencyMode were set to Single. We were hopping that we could stay way from the Single Instance/Single Thread because that would impose a lag on our processing time.

    Let me know if I can provide more details.

    Thanks!

    Tuesday, July 2, 2013 2:39 PM
  • Hi,

    Have you see the article in: http://msdn.microsoft.com/zh-cn/library/windowsazure/hh532034.aspx  .

    That msdn article use the function as you, but it can work well. So please try to check it again.


    Thanks.

    Best Regards. 



    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by dns jinung Thursday, July 18, 2013 2:56 AM
    Wednesday, July 3, 2013 5:22 AM
    Moderator
  • Amy,

    Thanks for the link. 

    You are right, the code works just fine with one or with a low number of messages. The problem just manifests when the concurrency level is high and the WCF Service has to process a large number of messages. 

    What can we do to diagnose the issue?

    Joao

    Wednesday, July 3, 2013 10:54 AM
  • Hi,

    For the large number, could you please try to increase some setting in configure file as following?

    <netMessagingBinding>
           <binding name="yourBinding"
                 closeTimeout="00:01:00" openTimeout="00:01:00"
                 receiveTimeout="00:01:00" sendTimeout="00:01:00"
                 prefetchCount="-1" sessionIdleTimeout="00:01:00"
                 maxReceivedMessageSize="10000000" 
                 maxBufferSize="10000000"
                 maxBufferPoolSize="10000000">
            
           <transportSettings batchFlushInterval="00:00:01" />
         </binding>
       </netMessagingBinding>

    Hope it can help you.

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Monday, July 8, 2013 5:44 AM
    Moderator
  • Amy,

    Regrettably the netMessagingBinding does not support these settings: maxReceivedMessageSize="10000000" maxBufferSize="10000000" maxBufferPoolSize="10000000"

    My config is:

    <netMessagingBinding>        
      <binding name="messagingBinding"
               closeTimeout="00:03:00" 
               openTimeout="00:03:00"
               receiveTimeout="00:03:00"
               sendTimeout="00:03:00"
               sessionIdleTimeout="00:01:00"
               prefetchCount="-1">          
        <transportSettings batchFlushInterval="00:00:01"/> 
     </binding>      
    </netMessagingBinding>
    Thanks.

    Monday, July 8, 2013 8:41 AM
  • Hi,

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Tuesday, July 9, 2013 1:50 AM
    Moderator
  • Thank you Amy. 

    Looking forward to hearing from you.

    Tuesday, July 9, 2013 6:24 AM

  • I just submitted a support request through our MSDN subscription. 

    I'll let you know the outcome.
    • Proposed as answer by dns jinung Thursday, July 18, 2013 2:56 AM
    Tuesday, July 9, 2013 3:26 PM
  • Hi,

    Ok, I will wait for your outcome. And I will let my leader to help you also.

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, July 11, 2013 3:10 AM
    Moderator
  • Hi JC,

    I researched a bit on this subject and based on this document the service needs to be decorated with the following attributes.

    [OperationContract(IsOneWay = true)]

    [ReceiveContextEnabled(ManualControl = true)]

    Could you please check this article and see if it solves your problem.

    http://msdn.microsoft.com/en-us/library/windowsazure/hh709041.aspx

    Thursday, August 1, 2013 5:43 AM
  • Hello Angshuman,

    Thanks for your response. Unfortunately, I'm already using both attributes in my interface.  

    I believe this issue only happens under load. Could it have something to do with the time-outs defined?  At the moment I'm using 10s on the Context.Complete/Abandon calls.

    Thanks,

    JCS


    Thursday, August 1, 2013 10:43 AM