开发者

Custom FaultContract returned as ExceptionDetail

开发者 https://www.devze.com 2023-04-03 19:11 出处:网络
I am trying to throw a custom FaultContract from a WCF service to a ASP.NET application, using Tcp Binding.

I am trying to throw a custom FaultContract from a WCF service to a ASP.NET application, using Tcp Binding.

I have defined the fault contract-

[DataContract]
public class CustomFault
{
    [DataMember]
    public string SomeData { get; set; }

    public CustomFault(string someData)
    {
        SomeData = someData;
    }
}

I have sp开发者_运维技巧ecified the fault contract on the service operation:

[OperationContract]
[FaultContract(typeof(CustomFault))]
void AddProductToBasket(Guid basketId, int productId, decimal quantity, int uomId);

I am throwing it like:

throw new FaultException<CustomFault>(new CustomFault("LowStock"));

And trying to catch it like this:

try
{
    // Do service operation.
}
catch (FaultException<CustomFault> fault)
{
    // Successfully caught typed FaultException<CustomFault>
    throw;
}
catch (Exception ex)
{
    // Failed, caught FaultException<ExceptionDetail>
    throw;
}

But the catch always catches something of type FaultException<ExceptionDetail>, I believe this happens when you specify <serviceDebug includeExceptionDetailInFaults="true" />, which I have done for other exceptions, but having specified the FaultContract for the operation it should use the custom FaultContract instead...

Anyone got any ideas?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号