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(details , new FaultReason(details .Message), new FaultCode("MyFault")); }
|
Client side:
try { // Obv proxy init etc.. service.ThrowException(); } catch (FaultException 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/ThrowExceptionMyFaultDetails" name=" MyFaultDetails " message="tns:IAnyJobService_ThrowException_MyFaultDetails_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=" MyFaultDetails "> <soap:fault use="literal" name=" MyFaultDetails " namespace="" /> </wsdl:fault> </wsdl:operation>
|
Any help ?
Thanks in advance
Regards
Alessandro