0
votes

I am building WCF pox and json rest service using WebScriptServiceHostFactory in framework 3.5 and i am sending the status code to client by throwing WebProtocolException. While doing so the exception is not well formatted and looks bad on the browser like below.....

Is there a way by which i format the exception on browser or suppress the exception in service and send only the status code to client.

{"ExceptionDetail":{"HelpLink":null,"InnerException":{"HelpLink":null,"InnerException": null,"Message":"Exception of type 'System.Exception' was thrown.","StackTrace":null, "Type":"System.Exception"},"Message":"SomeDescription","StackTrace":" at Platform.Licensing.Services.AuthorizationAttribute.BeforeCall(String operationName, Object[] inputs) in D:\Projects\trunk-LicensingAPI\Code\Platform.Licensing.Services\AuthorizationAttribute.cs:line 72\u000d\u000a at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InspectInputsCore(MessageRpc& rpc)\u000d\u000a at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)\u000d\u000a at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)\u000d\u000a at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)\u000d\u000a
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)", "Type":"Microsoft.ServiceModel.Web.WebProtocolException"},"ExceptionType": "Microsoft.ServiceModel.Web.WebProtocolException","Message":"SomeDescription", "StackTrace":" at Platform.Licensing.Services.AuthorizationAttribute.BeforeCall(String operationName, Object[] inputs) in D:\Projects\trunk-LicensingAPI\Code\\AuthorizationAttribute.cs:line 72\u000d\u000a
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InspectInputsCore(MessageRpc& rpc)\u000d\u000a at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)\u000d\u000a
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)\u000d\u000a at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)\u000d\u000a
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)"}

1

1 Answers

0
votes

This exception is due to multiple reasons. I was using the Factory along with the service configuration which was wrong. Also i had to make includeExceptionDetailInFaults = false and use custom behaviour and IErrorHandler to handle the WebProtocolException for rest.