views:

114

answers:

1

Hello, my problem is following:

While updateing service reference of my WCF client (simply by clicking Update Service Reference in Visual Studio 2008), I'm getting following error:

System.ServiceModel.FaultException: 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). at System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(Exception e, Message message)

Previously I've created ErrorServiceBehaviour class. This behavior is created for error handling so IErrorHandler implementation must be applied to each ChannelDispatcher.

public class ErrorServiceBehaviour : Attribute, IServiceBehavior
{
   //...
   public Type FaultType
   {
      get { return _faultType; }
      set { _faultType = value; }
   }

   public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
   {
       foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
       {
           dispatcher.ErrorHandlers.Add(new ErrorHandler(_faultType));
       }
   }
}

public class ErrorHandler : IErrorHandler
{
     public ErrorHandler(Type faultType)
     {
        _faultType = faultType;         
     }
     //...
}

I'm later using that behaviour by applying ErrorServiceBehavior attribute to my service class:

[ErrorServiceBehavior(FaultType = typeof(MyServiceFault))] 
public class MyService : IMyService
{
   //...
}

The funny thing is when I comment out the foreach loop inside ApplyDispatchBehavior method, I get NO error, but that is obviously not the way out because I want my errors to be handled.

Below is my service config:

<system.serviceModel>
    <services>
        <service behaviorConfiguration="DefaultBehavior" name="MyService">
            <endpoint address="" binding="wsHttpBinding" contract="IMyService" bindingConfiguration="NoSecurityBinding"/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="DefaultBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <wsHttpBinding>
            <binding name="NoSecurityBinding" >
                <security mode="None">
                    <transport clientCredentialType="None"/>
                    <message establishSecurityContext="false"/>
                </security>
            </binding>
            <binding name="DefaultBinding" />
        </wsHttpBinding>
    </bindings>
</system.serviceModel>

Can someone help me ?

UPDATE

The code below (shown earlier):

foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
{
    dispatcher.ErrorHandlers.Add(new ErrorHandler(_faultType));
}

adds custom error handling for all endpoints - including the metadata one. But this is not the source of the problem, because even when I disable adding error handling for metadata endpoint, this annoying problem still occurs. So it is just explanation in case of.

But the funny thing is, when I change the bindingConfiguration of the first endpoint to DefaultBinding, I have NO error at all:

<services>
    <service behaviorConfiguration="DefaultBehavior" name="MyService">
        <endpoint address="" binding="wsHttpBinding" contract="IMyService" bindingConfiguration="DefaultBinding"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
</services>

So wonderful, but this in obviously not the configuration I want, because I need old configuration without security (NoSecurityBinding), which is error prone for some reason.

Mabye this is a clue for someone to help me resolve the case.

Thanks in advance.