Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In .NET web services, how can the SoapException.Message property be easily readable?

I am writing an ASP.NET web service and am throwing a SoapException with a message:

throw new SoapException("BANG!", SoapException.ClientFaultCode);

When I create an ASP.NET client, and request a label to display the SoapException.Message property, it displays a message similar to the following:

System.Web.Services.Protocols.SoapException: BANG! at WebServiceException.WebService1.HelloWorld() in [DIRECTORY]\WebService1.asmx.cs:line 23

Is there an easy way to simply be presented with the message BANG! rather than this entire string? Or should I just use regular expressions?

like image 971
BWHazel Avatar asked Sep 25 '10 00:09

BWHazel


1 Answers

If you configure your web service to turn on custom error messages, the stack trace will not be present in the SOAP fault, which in turn will mean your client will not see it.

In web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    ...
    <system.web>
        ...
        <customErrors mode="On"/>
        ...
    </system.web>
    ...
</configuration>
like image 66
GBegen Avatar answered Nov 11 '22 16:11

GBegen