Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / August 2005

Tip: Looking for answers? Try searching our database.

How to customize the XML error message?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jaime Stuardo - 26 Aug 2005 14:57 GMT
Hi all....

When I explicitly throw an exception from my Web Service, this XML is sent:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server<
/faultcode><faultstring>System.Web.Services.Protocols.SoapException
:
Server was unable to process request. --->
System.Data.SqlClient.SqlException: El beneficiario requerido no existe en el
sistema de VidaSecurity
  at beneficiario.Ejecuta(String store_proc, Boolean aprobacion)
  at beneficiario.ObtienePago()
  at convenio.Consulta(QueryType datos)
  --- End of inner exception stack trace ---</faultstring><detail
/></soap:Fault></soap:Body></soap:Envelope>

As you see, faultstring tag contains very technical information that is not
useful for the user. Is it possible to change the level of error message so
that only my customized message is shown in faultstring tag?

Thanks
Jaime
Andrew Backer - 28 Aug 2005 21:37 GMT
Aren't these type of exceptions exactly what is supposed to be thrown?
How would you have .net put something more friendly in an unhandled
exception?  You are just going to have to trap likely exceptions (as
you should be doing with security exceptions, right?), and then throw a
custom SoapException that your app knows how to respond to.   There may
be a more elegant way to handle error codes in soap, but it seems like
using custom soapExceptions was the easiest way in .net

The only thing I ran into is the fact that the error code can not be
entirely numeric, so "e001" was necessary.  There are a few other fun
things about parsing one of the fields, but just throw one that you
make and check out every field of the returned exception for what you
need.
Michael Nemtsev - 30 Aug 2005 09:33 GMT
Hello Jaime,

You can customize you error by using XmlQualifiedName

and includind this instance to the SoapException

JS> When I explicitly throw an exception from my Web Service, this XML
JS> is sent:
JS>
JS> As you see, faultstring tag contains very technical information that
JS> is not useful for the user. Is it possible to change the level of
JS> error message so that only my customized message is shown in
JS> faultstring tag?
---
WBR,
Michael  Nemtse
Andrew Backer - 30 Aug 2005 19:01 GMT
In more detail, here is ~approx what I do.

On the server I throw this type of exception (i have a wrapper class
that derives from soapException, and helpers) :

throw new SoapException( "Mesage Here", new XmlQualifiedName("ERR_001",
"App/Server/Excep"));

On the client I do something like this to grab and extract the error :
try {
   call WS
} catch ( SoapException ex ) {
   switch ( ex.Code.Name.Trim() ) {
        case "ERR_001": // do something
...

Hope this helps.  I use more descriptive names that ERR_001 too.  There
may be funner ways to do this, but I'm new at WS so i'm not sure.  I
would like to catch a subclassed SoapException actually, but not sure
If I can do that.  

- Andrew

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.