I am migrating a web service client from WSE to WCF.
I already modified the internal fault and error handling to deal with FaultExceptions instead of SoapExceptions.
The project has an extensive suite of test cases to test the fault and error handling which still relies on SoapException. For various reasons, I'd prefer not to rewrite them all.
Is it possible to just convert the SoapException into a FaultException and thereby running the old test cases against the new error handling code?
how about
catching SoapException
and throwing FaultException
(a solution, not recommendation)
catch(SoapException)
{
throw new FaultException(); // something similar
}
What about using a message inspector ? Have you checked the IClientMessageInspector ?
It may look like this :
The message inspector
public class MessageInspector : IClientMessageInspector
{
...
#region IClientMessageInspector Members
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
//rethrow your exception here, parsing the Soap message
if (reply.IsFault)
{
MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
Message copy = buffer.CreateMessage();
reply = buffer.CreateMessage();
object faultDetail = //read soap detail here;
...
}
}
#endregion
...
}
The endpoint behavior
public class MessageInspectorBehavior : IEndpointBehavior
{
...
#region IEndpointBehavior Members
public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
{
MessageInspector inspector = new MessageInspector();
clientRuntime.MessageInspectors.Add(inspector);
}
#endregion
...
}
http://weblogs.asp.net/paolopia/archive/2007/08/23/writing-a-wcf-message-inspector.aspx
I think a good practice is to use exceptions as faults too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With