简体   繁体   English

EndpointDispatcher上的ContractFilter不匹配(错误处理)

[英]ContractFilter mismatch at the EndpointDispatcher (error handling)

While updating a service reference of my WCF client (simply by clicking Update Service Reference in Visual Studio 2008), following error occurs: 在更新我的WCF客户端的服务引用时(只需单击Visual Studio 2008中的“ 更新服务引用” ),会发生以下错误:

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. System.ServiceModel.FaultException:由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理具有Action“ http://schemas.xmlsoap.org/ws/2004/09/transfer/Get ”的消息。 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). 检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无)。 at System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(Exception e, Message message) 在System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(例外e,消息消息)

Background: 背景:

I've created ErrorServiceBehaviour class. 我创建了ErrorServiceBehaviour类。 Because such a behavior is created for error handling, IErrorHandler implementation must be applied to each ChannelDispatcher . 由于为错误处理创建了此类行为, IErrorHandler必须将IErrorHandler实现应用于每个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;         
     }
     ...
}

Later, I've used that behaviour by applying ErrorServiceBehavior attribute to my service class: 后来,我通过将ErrorServiceBehavior属性应用于我的服务类来使用该行为:

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

The thing is, when I comment out the foreach loop inside ApplyDispatchBehavior method, I get no error at all, but that is not the way out (because I want my errors to be handled). 问题是,当我在ApplyDispatchBehavior方法中注释掉foreach循环时,我根本没有得到任何错误,但这不是出路(因为我希望我的错误得到处理)。

Below there 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 UPDATE

The code 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 actually this is not the source of the problem - even when I disable adding error handling for metadata endpoint, the issue still occurs. 但实际上这不是问题的根源 - 即使我禁用了为元数据端点添加错误处理,问题仍然存在。

The other notice is, when I change the bindingConfiguration of the first endpoint to DefaultBinding , I have no error at all: 另一个注意事项是,当我将第一个端点的bindingConfiguration更改为DefaultBinding ,我完全没有错误:

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

Such an option in also not what I want - I still need problematic NoSecurityBinding to work. 这样的选择也不是我想要的 - 我仍然需要有问题的NoSecurityBinding才能工作。

Thanks in advance. 提前致谢。

To begin with, I notice your try to bind a mexHttpBinding to an endpoint although it was never defined inside your "Bindings" tag. 首先,我注意到您尝试将mexHttpBinding绑定到端点,尽管它从未在“Bindings”标记内定义。 This should rise an exception, and I would expect such an exception to look like the one that's bothering you. 这应该是一个异常,我希望这样的例外看起来像是困扰你的那个。

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

...

<bindings>
    <mexHttpBinding>
        THIS TAG WAS MISSING (add security features as needed)
    </mexHttpBinding>

    <basicHttpBinding>
        <binding name="NoSecurityBinding" >
            <security mode="None" />
        </binding>
        <binding name="DefaultBinding" />
    </basicHttpBinding>
</bindings>

Also, since you apparently dont need any security feature, you might want to favor basicHttpBinding. 此外,由于您显然不需要任何安全功能,您可能希望支持basicHttpBinding。 As this very thorough answer states, wsHttpBinding really is useful when you want security features. 正如这个非常彻底的答案所述,当您需要安全功能时,wsHttpBinding非常有用。

Your configuration would end up being almost the same, changing "ws" for "basic". 您的配置最终会变得几乎相同,将“ws”更改为“basic”。

<system.serviceModel>
<services>
    <service behaviorConfiguration="DefaultBehavior" name="MyService">
        <endpoint address="" binding="basicHttpBinding" 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>
    <basicHttpBinding>
        <binding name="NoSecurityBinding" >
            <security mode="None" />
        </binding>
        <binding name="DefaultBinding" />
    </basicHttpBinding>
</bindings>

检查App.Config并验证它是否指向已部署的Windows服务主机或将其设置为指向localhost

Look into the IExtensibleDataObject , it is used to handle different versions of a web service still being able to communicate with each other. 查看IExtensibleDataObject ,它用于处理仍然能够相互通信的Web服务的不同版本。 This way the contracts don't need to match exactly. 这样合同就不需要完全匹配。 Hope this helps. 希望这可以帮助。

On what you say it seems that your new WCF service do require security and in your NoSecurityBinding you turn it off. 根据您的说法,您的新WCF服务似乎确实需要安全性,而在NoSecurityBinding中您可以将其关闭。 One way to check that is to get WSDL file locally an see if it has: http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd or http://schemas.xmlsoap.org/ws/2004/09/policy or something like that in imports. 检查它的一种方法是在本地获取WSDL文件,看看它是否有: http//docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsdhttp ://schemas.xmlsoap.org/ws/2004/09/policy或类似的导入内容。 I'm pretty sure that your updated WCF service has security enabled 我很确定您更新的WCF服务已启用安全性


Update 1 更新1

To get a better vision of your problem you could use WCF Tracing. 为了更好地了解您的问题,您可以使用WCF跟踪。 Here you could see how to turn it on and how to read that traces: "How to turn on WCF tracing" 在这里,您可以看到如何打开它以及如何读取跟踪: “如何打开WCF跟踪”

I don't think you are turning the security completely off. 我不认为你完全取消了安检。 Try this: 尝试这个:

<bindings>
        <wsHttpBinding>
            <binding name="NoSecurityBinding" >
                <security mode="None">
                    <transport clientCredentialType="None"/>
                    <message clientCredentialType="None"/>
                </security>
            </binding>
            <binding name="DefaultBinding" />
        </wsHttpBinding>
    </bindings>

Existing web.config setting can create a problem as they are for previous version. 现有的web.config设置可能会产生问题,因为它们适用于以前的版本。 Better to remove existing reference from your WCF client application and Add the reference again. 最好从WCF客户端应用程序中删除现有引用并再次添加引用。

<services>
  <service behaviorConfiguration="ServiceBehaviour" name="Service">
    <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" contract="IService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

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

相关问题 WCF ContractFilter 在 EndpointDispatcher 错误处不匹配 - WCF ContractFilter mismatch at the EndpointDispatcher error 在EndpointDispatcher上ContractFilter不匹配? - ContractFilter mismatch at the EndpointDispatcher? EndpointDispatcher上的ContractFilter不匹配 - ContractFilter mismatch at the EndpointDispatcher WCF- ContractFilter在EndpointDispatcher上不匹配 - WCF- ContractFilter mismatch at the EndpointDispatcher 由于EndpointDispatcher的ContractFilter不匹配,因此无法在接收方处理带有动作&#39;&#39;的消息。 - The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. 由于EndpointDispatcher的ContractFilter不匹配,带有Action的消息无法在接收方处理 - The message with Action cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher 服务客户端通信上的ContractFilter不匹配错误 - ContractFilter mismatch error on service client communication WCF ContractFilter不匹配 - WCF ContractFilter mismatch 错误由于EndpointDispatcher的AddressFilter不匹配,带有To&#39;&#39;的消息无法在接收方处理 - Error The message with To '' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher 启用可靠 Session 时 WCF 合同过滤器不匹配 - WCF ContractFilter Mismatch when enabling Reliable Session
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM