开发者

Handle WCF exceptions from webservice proxy

I have a WCF service (.NET 4) hosted in IIS. My service contract has one method with:

[FaultContract(typeof(string))]

My service implementation for that method validates input parameters and may throw an exception like this:

if (string.IsNullOrWhiteSpace(siteName)) { throw new FaultException("siteName is re开发者_如何学Goquired."); }

The consumer program of this service is a .NET 2 console application. In this app I generated the webservice proxy by right clicking "References" and "Add web reference".

When I try to call the service method from the client app, by sending an invalid siteName, I get back a 503 Service Unavailable exception, instead of a FaultException with the custom error message.

How can I make the FaultException, with the custom error message, propagate to the client program?

UPDATE:

The exception I get in the client application is this:

System.ServiceModel.ServerTooBusyException: The HTTP service located at http://www.example.com/services/myservice.svc is too busy. ---> System.Net.Web Exception: The remote server returned an error: (503) Server Unavailable.

at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpCha nnelRequest.WaitForReply(TimeSpan timeout) --- End of inner exception stack trace ---


The problem was being caused by a custom HTTP module in our web project. So it was not exactly a WCF problem, but a problem specific to our solution. Thanks!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜