EndpointDispatcher上的WCF和ContractFilter不匹配

时间:2013-03-20 17:43:58

标签: wcf wcf-binding

我得到了以下错误......问题是什么?

  由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理带有Action''的消息。这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配。检查发件人和收件人是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无)。

  1. WSModules.svc

    <%@ ServiceHost language="C#" Service="WS.Modules.ServiceContracts.WSModules"%>
    
  2. WSModules

    namespace WS.Modules.ServiceContracts
    {
        [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
        public class WSModules : IWSModules
        {  
            public string XmlData(string id)
            {
                return "You requested product" + id;
            }
        }
    }
    
  3. IWSModules

    namespace WS.Interfaces.ServiceContracts
    {
            [ServiceContract]
            public interface IWSModules
            {
                    [OperationContract]
                    [WebGet(UriTemplate = "XmlData?id={id}")]
                    string XmlData(string id);
            }
    }
    
  4. 的Web.config

    <system.serviceModel>   
    <behaviors>
    <serviceBehaviors>       
            <!-- ### WSModules -->
            <behavior name="WSModulesBehavior">
              <serviceMetadata httpGetEnabled="True" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceThrottling maxConcurrentCalls="24" maxConcurrentSessions="24" />
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="web">
              <webHttp/>
            </behavior>
          </endpointBehaviors>      
        </behaviors>
    <services>   
          <!--  ### WSModules Service-->
          <service behaviorConfiguration="WSModulesBehavior" name="WS.Modules.ServiceContracts.WSModules">
            <endpoint address="" binding="webHttpBinding" contract="WS.Interfaces.ServiceContracts.IWSModules"/>       
                    <host>
                      <baseAddresses>
                        <add baseAddress="http://xxx.xxx.xxx/commonwebsol/wswsdl" />
                      </baseAddresses>
                    </host>
                  </service>
                </services>
                <serviceHostingEnvironment multipleSiteBindingsEnabled="True"/>
              </system.serviceModel>
    
  5. 我打开浏览器并输入 http://xxx.xxx.xxx/commonwebsol/WSWSDL/WSModules.svc - 工作正常。 我收到了“svcutil.exe http://xxx.xxx.xxx/commonwebsol/WSWSDL/WSModules.svc?wsdl 然后,如果我点击“http://xxx.xxx.xxx/commonwebsol/WSWSDL/WSModules.svc?wsdl”我得到了xml

  6. 但是如果我进入探索浏览器 http://xxx.xxx.xxx/commonwebsol/WSWSDL/WSModules.svc?XmlData?id=123 我收到了以下错误...

    <Text xml:lang="en-US">The message with Action '' 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).</Text> 
    

1 个答案:

答案 0 :(得分:0)

更改您的端点属性,如下所示

endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" contract="WS.Interfaces.ServiceContracts.IWSModules" 

这样可以正常工作。