简体   繁体   中英

WCF ContractFilter mismatch

I am hosting a WCF service on IIS. I can access the wsdl file with my browser. I can also add the Service Reference in Visual Studio for my client.

However, if I try to call Server.Test() an ActionNotSupportedException is thrown:

The message with Action ' http://tempuri.org/IWCFService/Test ' 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, eg Message, Transport, None).

I have two endpoints defined: One TCP.NET for the communication between the service and the client and one HTTP for metadata exchange.

Server Configuration (web.conf)

<services>
  <service behaviorConfiguration="MyBehavior"
  name="WCFServiceLibrary.Service.WCFService">
    <endpoint address=""
          binding="netTcpBinding"
          bindingConfiguration="MyServiceEndpoint"
          name="MyServiceEndpoint"
          contract="WCFServiceLibrary.Contract.IWCFService">
    </endpoint>

    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

    <host>
      <baseAddresses>
        <add baseAddress="http://192.168.0.5:8080/Service.svc" />
      </baseAddresses>
    </host>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="MyBehavior">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Client Configuration (app.conf)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="MyServiceEndpoint">
          <security mode="None" />
        </binding>
      </netTcpBinding>
    </bindings>

    <client>
      <endpoint address="net.tcp://192.168.0.5:808/Service.svc" binding="netTcpBinding"
          bindingConfiguration="MyServiceEndpoint" contract="ServiceReference.IWCFService"
          name="MyServiceEndpoint" />
    </client>

  </system.serviceModel>
</configuration>

In IIS I have set net.tcp (808:*) binding as well as http (8080) binding.

Sorry, nothing jumps out at me, but if I may suggest you set up tracing on the client, it should tell you what the actual problem is:

http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx

Just a side note it seems to be the trend nowadays to reference the contract dll's in the client rather than use wsdl.

Shouldn't the baseaddress in web.config of the wcf service:

<host>
      <baseAddresses>
        <add baseAddress="http://192.168.0.5:8080/Service.svc" />
      </baseAddresses>
</host>

be "net.tcp://..."

<host>
      <baseAddresses>
        <add baseAddress="net.tcp://192.168.0.5:8080/Service.svc" />
      </baseAddresses>
</host>

简单重启服务器就可以了!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM