简体   繁体   English

WCF ContractFilter不匹配

[英]WCF ContractFilter mismatch

I am hosting a WCF service on IIS. 我在IIS上托管WCF服务。 I can access the wsdl file with my browser. 我可以使用浏览器访问wsdl文件。 I can also add the Service Reference in Visual Studio for my client. 我还可以在Visual Studio中为客户端添加服务引用。

However, if I try to call Server.Test() an ActionNotSupportedException is thrown: 但是,如果我尝试调用Server.Test(),则会引发ActionNotSupportedException:

The message with Action ' http://tempuri.org/IWCFService/Test ' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. 由于EndpointDispatcher的ContractFilter不匹配,带有Action'http: //tempuri.org/IWCFService/Test '的消息无法在接收方处理。 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. 我定义了两个端点:一个用于服务与客户端之间通信的TCP.NET,另一个用于元数据交换的HTTP。

Server Configuration (web.conf) 服务器配置(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) 客户端配置(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. 在IIS中,我设置了net.tcp(808:*)绑定以及http(8080)绑定。

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 http://msdn.microsoft.com/zh-CN/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. 只是附带说明,当今看来,在客户端中引用合同dll而不是使用wsdl是一种趋势。

Shouldn't the baseaddress in web.config of the wcf service: wcf服务的web.config中的基址不应该:

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

be "net.tcp://..." 是“ net.tcp:// ...”

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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