A web service running in IIS but through a factory doesn’t keep up the original exception thrown.
For example:
My web service has been marked up with FaultContractAttribute like this way:
public interface IMyService
{
[FaultContract(typeof(MyCustomException))]
[OperationContract]
bool IsAuthorized();
}
My web service implementation has throws out a custom exception like this way:
public class MyService : IMyService
{
public bool IsAuthorized()
{
throw new FaultException<MyCustomException>(fault, fr);
}
}
Then:
-
If my WCF – NOT using any factory – is similar to
<%@ ServiceHost Language="C#" Debug="true" Service="MyService" %>, then on client side I CAN pick up the original exception (MyCustomException) -
If my WCF – USING some factory – is similar to
<%@ ServiceHost Language="C#" Debug="true" Service="MyService" Factory="MyFactory" %>, then on client side I CAN’T pick up the original exception (MyCustomException) but only SOAP exception (FaultException) with useless general trace & message
Note:
WCF factory MyFactory is implemented with its SERVICE HOST contains a SERVICE BEHAVIOR initiated from IErrorHandler
In this service behavior, method ProvideFault does nothing (I haven’t known how to keep up the original exception by this way)
In summary, I beg answers from expects: How to keep up the original exception (MyCustomException) while using some WCF factory ?
Thanks.
In my recent project (WCF REST services) I use WebServiceHostFactory and I still was able to achieve this using IErrorHandler. Find below a sample
I created a class ExceptionInfo that could be serialized and sent back to the client.
And implementing a custom error handler
Now you can decorate your services using the above handler.
On the client side, you can check if the HttpStatusCode of the response != Ok and deserialize the response to ExceptionInfo type and display in a message box or handle per requirement.
Hope this helps.