none
Self-hosted WCF Service - Clustered Environment

    Question

  • Hello,

    I developed a self-hosted Windows Service WCF application that basically just exposes some interface to the WPF client (authentication, report viewing, etc.). The configuration on my service is stated below:

    <system.serviceModel>
    
        <services>
          <service name="WcfNamespace.MyService"
                   behaviorConfiguration="WcfNamespace.MyServiceBehavior">
    
            <host>
              <baseAddresses>
                <add baseAddress="https://www.myproductionurl.com/MyService"   />
              </baseAddresses>
            </host>
    
            <endpoint address=""
                      bindingNamespace="https://www.myproductionurl.com/MyService"
                      binding="wsHttpBinding"
                      bindingConfiguration="MyWsHttpBinding"
                      name="wsHttpEndpoint"
                      contract="WcfNamespace.Contracts.IKioskService"
                      behaviorConfiguration="MyEndpointBehavior">
            </endpoint>
    
            <endpoint address="mex"
                      binding="mexHttpsBinding"
                      name="MexHttpsBindingEndpoint"
                      contract="IMetadataExchange"/>
    
          </service>
        </services>
    
        <behaviors>
          <endpointBehaviors>
            <behavior name="MyEndpointBehavior">
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="WcfNamespace.MyServiceBehavior">
              <serviceMetadata httpGetEnabled="False" httpsGetEnabled="True" />
              <serviceDebug includeExceptionDetailInFaults="False" />
              <dataContractSerializer maxItemsInObjectGraph="2147483647"  />
            </behavior>
          </serviceBehaviors>
        </behaviors>
    
        <bindings>
          <wsHttpBinding>
            <binding name="MyWsHttpBinding"
                     receiveTimeout="01:00:00"
                     openTimeout="01:00:00"
                     closeTimeout="01:00:00"
                     sendTimeout="01:00:00"
                     maxBufferPoolSize="2147483647"
                     maxReceivedMessageSize="2147483647"
                     messageEncoding="Mtom" 
                     >
              <security mode="Transport">
                <message establishSecurityContext="false" />
                <transport clientCredentialType="None" />
              </security>
              <readerQuotas maxArrayLength="2147483647"
                            maxDepth="2147483647"
                            maxBytesPerRead="2147483647"
                            maxNameTableCharCount="2147483647"
                            maxStringContentLength="2147483647"/>
            </binding>
          </wsHttpBinding>
        </bindings>
      </system.serviceModel>

    This works fine in a non-clustered environment but when deployed to the production server (3 nodes - clustered server) it is not working. The client cannot authenticate or get any result from any of the interface exposed in the server.

    Sometimes we get this error even though the service is running for the 3 nodes when investigated and accessing the WCF service endpoint URL directly in the browser is working fine.

    "An error occurred while receiving the HTTP response to https://www.myproductionurl.com/MyService. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down"

    I am new to WCF obviously and also somehow I tried to set the keepAliveEnabled to false but still no luck using Custom Binding.

    <customBinding>
    <binding name="MyCustomBinding"
    		 receiveTimeout="01:00:00"
    		 openTimeout="01:00:00"
    		 closeTimeout="01:00:00"
    		 sendTimeout="01:00:00">
      <mtomMessageEncoding maxBufferSize="2147483647"
    					   maxWritePoolSize="2147483647"
    					   maxReadPoolSize="2147483647">
    	<readerQuotas maxArrayLength="2147483647"
    				  maxDepth="2147483647"
    				  maxBytesPerRead="2147483647"
    				  maxNameTableCharCount="2147483647"
    				  maxStringContentLength="2147483647"/>
      </mtomMessageEncoding>
      <httpsTransport authenticationScheme="Anonymous"
    				  transferMode="Streamed"
    				  keepAliveEnabled="false"
    				  maxReceivedMessageSize="2147483647"
    				  maxBufferSize="2147483647"
    				  maxBufferPoolSize="2147483647"
    				  />
    </binding>
    </customBinding>

    I have read couple of articles including the forum thread that is related to this topic but with no luck and some I am not sure if related to this problem. 

    Please let me know what am I missing as this is going nuts already for almost 2 days. Thanks.


    jeudi 12 avril 2012 15:34

Toutes les réponses

  • hi

    Is there a load balancer?

    When you turn off security does it work?

    Turn on WCF log and trace on the server(s) to see what error they contain.

    Yaron


    http://webservices20.blogspot.com/
    WCF Security, Interoperability And Performance Blog

    jeudi 12 avril 2012 20:13
  • You need to check whether you have any object in DataContract which can be serialized. or try increasing the value of maxRequestLength in httpRuntime and timeouts and buffer sizes. As Yaron Naveh metioned, you'd better enable WCF tracing at the server side to see the inner detailed error information to find some indicates.

    #enable WCF tracing.
    http://blogs.msdn.com/b/madhuponduru/archive/2006/05/18/601458.aspx

    You can also check this article.
    http://www.creativecodedesign.com/node/58


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    vendredi 13 avril 2012 05:55
    Modérateur
  • Hello Yaron, I am not actually sure if there is a load balancer in our production server probably turning on the WCF log would help trace the real problem. 

    I'll get back to you once I found the error details.

    vendredi 13 avril 2012 06:36
  • Hi Peter,

    I think I have increased the sizes as per my configuration sample (first post) since we have encountered issues before regarding that and so every timeout and buffer size is set to "2147483647". Also set the data contract serializer max object graph size to "2147483647".

    Please elaborate when you say "You need to check whether you have any object in DataContract which can be serialized". I have data contracts object that is returned by the service that looks like the sample code below and so how do I determine if that needs to be serialized? please bare with me on this.

    [DataContract]
    public class MyObject
    {
    	[DataMember]
    	public DateTime TransDate { get; set; }
    
    	[DataMember]
    	public string Name { get; set; }
    }
    Thanks for the information about enabling the WCF tracing. I will try this out and get back to you as well.

    vendredi 13 avril 2012 06:48
  • As for that sentence, what I meaning is that you need to check the DataContract class as return type or parameter in WCF operations whether has other class object that cannot be serialized. But see the above DataContract class, all the class members can be serialized.


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    vendredi 13 avril 2012 06:56
    Modérateur
  • Ok, so should I leave it as is or I need to do something for the members to be serializable? As far as I know though, WCF Data contact serialization happens by default as long the types are supported.


     
    vendredi 13 avril 2012 08:28
  • Hi,

    I enabled the WCF tracing and I saw the following error messages from tracelog.svclog:

    Process action 'https://myproductionurl.com/MyService/IMyService/RsaEncrypt'.

    The message with Action 'https://myproductionurl.com/MyService/IMyService/RsaEncrypt' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

    Receive bytes on connection 'https://myproductionurl.com/MyService/_vti_bin/ListData.svc/$metadata'.

    There is a problem with the XML that was received from the network. See inner exception for more details.

    System.ServiceModel.Channels.HttpRequestContext.CreateMessage()
    System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)
    System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContextCore(IAsyncResult result)
    System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContext(IAsyncResult result)
    System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
    System.Net.LazyAsyncResult.Complete(IntPtr userToken)
    System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
    System.Net.ListenerAsyncResult.WaitCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
    System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

    Process action 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get'.

    "The message with Action 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)."

    mardi 17 avril 2012 06:56
  • in the clustered environment, when you have a client to by pass the lb and talk directly to the service, does it work? if so compare the message between working and non working clinet.

    one gotcha is that the ws addressing To header may be different. You may need to define a clientVia behavior on the client and a ListenUri on all servers. Each client states in the To header to which server it goes to. If you do not use clientVia then the server url will be the physical one (lb / proxy). the actual servers will reject that destination To. So you need to override on the client what it sends (clientVia) and on servers what they expect (ListenUri).

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


    http://webservices20.blogspot.com/
    WCF Security, Interoperability And Performance Blog

    mardi 17 avril 2012 14:39
  • The error illustrates that the receiver could not process the message because no contract claimed it.

    As the error message described, it may be caused by the following reasons.

    1. You have different contracts between client and sender.

    2. You’re using a different binding between client and sender.

    3. The message security settings are not consistent between client and sender.

    For more about this, here is a similar post to which you can refer.

    http://stackoverflow.com/questions/5487791/wcf-contractfilter-mismatch-at-the-endpointdispatcher-exception


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    • Marqué comme réponse dotnetnewby mercredi 25 avril 2012 10:59
    • Non marqué comme réponse dotnetnewby mercredi 25 avril 2012 11:00
    jeudi 19 avril 2012 05:43
    Modérateur
  • Thank Peter, I will look into the link you provided. However, just wondering how the first and second items happen. Our WPF client basically reference the same production URL specified in the service and so binding should also be the same. Please correct me if I am wrong here.
    jeudi 19 avril 2012 07:55
  • Thanks Yaron for the response. I am sorry I don't get what "lb" means, we only have one WPF client that is communicating to self hosted WCF  service with the settings as specified in the first post.
    jeudi 19 avril 2012 08:06
  • lb is load balancer, but it can be any router that decides to which of the 3 servers the client request will go.

    http://webservices20.blogspot.com/
    WCF Security, Interoperability And Performance Blog

    jeudi 19 avril 2012 14:01