jwa*_*zko 29 .net c# wcf web-services
在更新我的WCF客户端的服务引用时(只需单击Visual Studio 2008中的" 更新服务引用"),会发生以下错误:
System.ServiceModel.FaultException:由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理具有Action" http://schemas.xmlsoap.org/ws/2004/09/transfer/Get " 的消息.这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配.检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无).在System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(例外e,消息消息)
背景:
我创造了ErrorServiceBehaviour
课程.由于为错误处理创建了此类行为,因此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;
}
...
}
Run Code Online (Sandbox Code Playgroud)
后来,我通过将ErrorServiceBehavior
属性应用于我的服务类来使用该行为:
[ErrorServiceBehavior(FaultType = typeof(MyServiceFault))]
public class MyService : IMyService
{
...
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我foreach
在ApplyDispatchBehavior
方法中注释循环时,我根本没有得到任何错误,但这不是出路(因为我希望我的错误得到处理).
下面是我的服务配置:
<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>
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗?
UPDATE
前面显示的代码:
foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
{
dispatcher.ErrorHandlers.Add(new ErrorHandler(_faultType));
}
Run Code Online (Sandbox Code Playgroud)
为所有端点添加自定义错误处理 - 包括元数据.但实际上这不是问题的根源 - 即使我禁用了为元数据端点添加错误处理,问题仍然存在.
另一个注意事项是,当我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>
Run Code Online (Sandbox Code Playgroud)
这样的选择也不是我想要的 - 我仍然需要有问题NoSecurityBinding
才能工作.
提前致谢.