WCF Webservices and FaultContract - Client's receiving SoapExc insted of FaultException<TDetails>
Posted
by Alessandro Di Lello
on Stack Overflow
See other posts from Stack Overflow
or by Alessandro Di Lello
Published on 2010-04-15T09:49:08Z
Indexed on
2010/04/15
9:53 UTC
Read the original article
Hit count: 602
Hi All,
i'm developing a WCF Webservice and consuming it within a mvc2 application. My problem is that i'm using FaultContracts on my methods with a custom FaultDetail and i'm throwing manyally the faultexception but when the client receive the exception , it receives a normal SoapException instead of my FaultException that i throwed from the service side.
Here is some code:
Custom Fault Detail Class:
[DataContract]
public class MyFaultDetails
{
[DataMember]
public string Message { get; set; }
}
Operation on service contract:
[OperationContract]
[FaultContract(typeof(MyFaultDetails))]
void ThrowException();
Implementation:
public void ThrowException()
{
var details = new MyFaultDetails { Message = "Exception Test" };
throw new FaultException<MyFaultDetails >(details , new FaultReason(details .Message), new FaultCode("MyFault"));
}
Client side:
try
{
// Obv proxy init etc..
service.ThrowException();
}
catch (FaultException<MyFaultDetails> ex)
{
// stuff
}
catch (Exception ex)
{
// stuff
}
What i expect is to catch the FaultException , instead that catch is skipped and the next catch is taken with an exception of type SoapException.
Am i missing something ?
i red a lot of threads about using faultcontracts within wcf and what i did seems to be good. I had a look at the wsdl and xsd generated and they look fine. here's a snippet regarding this method:
<wsdl:operation name="ThrowException">
<wsdl:input wsaw:Action="http://tempuri.org/IAnyJobService/ThrowException" message="tns:IAnyJobService_ThrowException_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/IAnyJobService/ThrowExceptionResponse" message="tns:IAnyJobService_ThrowException_OutputMessage" />
<wsdl:fault wsaw:Action="http://tempuri.org/IAnyJobService/ThrowExceptionAnyJobServiceFaultExceptionFault" name="AnyJobServiceFaultExceptionFault" message="tns:IAnyJobService_ThrowException_AnyJobServiceFaultExceptionFault_FaultMessage" />
</wsdl:operation>
<wsdl:operation name="ThrowException">
<soap:operation soapAction="http://tempuri.org/IAnyJobService/ThrowException" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="AnyJobServiceFaultExceptionFault">
<soap:fault use="literal" name="AnyJobServiceFaultExceptionFault" namespace="" />
</wsdl:fault>
</wsdl:operation>
Any help ?
Thanks in advance
Regards
Alessandro
© Stack Overflow or respective owner