无法通过FaultException发现WCF服务

时间:2018-07-02 18:11:54

标签: c# .net wcf faultexception

我有一个WCF,可以通过Visual Studio中的“添加服务引用”完全发现它。然后,我添加了FaultException,但现在找不到了。有人知道为什么吗?

这是我的配置文件:

  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="customBinding" receiveTimeout="01:00:00" sendTimeout="01:00:00">
          <security mode="None" />
        </binding>
      </netTcpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="customBehavior">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="MyService.Service.Services.FooService" behaviorConfiguration="customBehavior">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="customBinding" contract="MyService.Contracts.IFooService" />
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:9000/FooService" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

我的合同和操作:

[ServiceContract]
public interface IFooService
{
    [OperationContract]
    [FaultContract(typeof(FooOperationException))]
    void FooOperation(FooDto fooId);
}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class FooService : BaseService, IFooService
{    
    public void FooOperation(FooDto fooId)
    {


    }
}    

public class FooOperationException : ApplicationException
{
    public FooOperationException(string message)
        : this(message, null)
    {
    }

    public FooOperationException(string message, Exception innerException)
        : base(message, innerException)
    {
    }
}

我不知道发生了什么。感谢您的帮助

0 个答案:

没有答案