2013-03-20 148 views
2

我得到了以下错误。问题是什么?WCF和ContractFilter不匹配在EndpointDispatcher

由于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. 但是如果我进入Explore浏览器 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> 
    

回答

0

更改您的端点属性,如下面

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

这将工作正常。