C# 如何克服System.ServiceModel.FaultException

C# 如何克服System.ServiceModel.FaultException,c#,web-services,wcf,C#,Web Services,Wcf,更新我的WCF客户端的服务引用时(只需在Visual Studio 2008中单击更新服务引用),会发生以下错误:System.ServiceModel.FaultException:消息 我创建了ErrorServiceBehavior类。因为这样的行为是为错误处理而创建的,所以IErrorHandler实现必须应用于每个ChannelDispatcher public class ErrorServiceBehaviour : Attribute, IServiceBehavior {

更新我的WCF客户端的服务引用时(只需在Visual Studio 2008中单击更新服务引用),会发生以下错误:System.ServiceModel.FaultException:消息

我创建了ErrorServiceBehavior类。因为这样的行为是为错误处理而创建的,所以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;         
     }
     ...
}
稍后,我通过将ErrorServiceBehavior属性应用于我的服务类来使用该行为:

[ErrorServiceBehavior(FaultType=typeof(MyServiceFault))]

public class MyService : IMyService
{
   ...
}
问题是,当我注释掉ApplyDispatchBehavior方法中的foreach循环时,我没有得到任何错误,但这不是解决方法(因为我希望我的错误得到处理)

下面是我的服务配置:

<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>

在代码中替换,然后尝试:

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


您的安全系统完全关闭了吗?我不明白。。你在说什么?我;我很困惑。你到底什么时候会犯错?请发布故障的完整信息。