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 / September 2003

Tip: Looking for answers? Try searching our database.

InnerException doesn't work with SoapException

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Henke - 12 Sep 2003 09:57 GMT
If you examine the SoapExeption contructor there is one that takes a
System.Exception (inner exception) as a parameter. What you could think is
that you could pass your user defined exception on the server and then on
the client you could retrive it to check what caused the error. But that
doesn't seem to work. Am I doing something wrong here or isn't it supposed
to be used this way.

If that's not the way to inform the client what went wrong, are there any
suggestions on how to do it?

Thanks!

/Henke
Eirik M. - 12 Sep 2003 13:36 GMT
I would like to know why this doesn't work too, as it is stalling a piece of
a project I'm working on. MS where are you?

Eirik M.

> If you examine the SoapExeption contructor there is one that takes a
> System.Exception (inner exception) as a parameter. What you could think is
[quoted text clipped - 9 lines]
>
> /Henke
CSharpTooth - 16 Sep 2003 00:04 GMT
Its not in the SOAP spec for the InnerException property to be returned.
You will have to implement a custom solution.  I did this and it works fine.
You basically create a function that returns an XmlNode and create your
fault details there.  Then when you throw a SoapException, you pass the
method call the XmlNode and the soap exception.

This will return your SOAP fault properly.  Now to get the values on the
client side, you will have to manually create a method to return your
details either as an XmlDocument, XmlNode, or specifically make properties
that correspond to your InnerException elements and parse them out upon
instantiation of your Proxy class.  When your Proxy gens a SoapException,
pass it to your custom handler.

As an example, for a custom innnerexception property
"InnerExceptionMessage", when you encounter the SoapException, pass it to
your exception handler

catch(System.Web.Services.Protocols.SoapException se){
   myExceptionHandler myeh = new myExceptionHandler(se);
   string myInnerExceptionMessage = myeh.InnerExceptionMessage;
}

Your exception handler constructor would look something like this...

public myExceptionHandler(SoapException se):base (se.Message, se.Code,
se.Actor, se.Detail, se.InnerException) {
   XmlNode nMessage = null;

   nMessage = se.Detail.SelectSingleNode("InnerExceptionMessage");
   if(nMessage != null){
       sMsg = nMessage.InnerText;
       if (sMsg != null)
           this.ieMsg= sMsg;
       }
   }

note the "ieMsg" is declared as a private string to return from your custom
property of your myExceptionHandler class...

public string InnerExceptionMessage {
   get {
       return ieMsg;
   }
}

Hope this helps.

--------------------------------------------------------
> If you examine the SoapExeption contructor there is one that takes a
> System.Exception (inner exception) as a parameter. What you could think is
[quoted text clipped - 9 lines]
>
> /Henke
Eirik M. - 17 Sep 2003 20:01 GMT
> Its not in the SOAP spec for the InnerException property to be returned.
> You will have to implement a custom solution.  I did this and it works fine.
> You basically create a function that returns an XmlNode and create your
> fault details there.  Then when you throw a SoapException, you pass the
> method call the XmlNode and the soap exception.

Can you elaborate on this? Do you mean "catch a SoapException"?

Eirik M.

> This will return your SOAP fault properly.  Now to get the values on the
> client side, you will have to manually create a method to return your
[quoted text clipped - 51 lines]
> >
> > /Henke
CSharpTooth - 21 Sep 2003 04:03 GMT
Yes,

When you create your Web Methods in your Web Service, and an error occurs,
use the try{} catch(Exception e){} block to catch the exception, then throw
a new soap exception.

Once you throw the new Soap Exception, you can create a custom method to
create the InnerException details as  a SOAP Fault XmlNode, then pass that
into the overloaded method for SoapException.

When the exception is found and you trap, then rethrow, your web proxy that
is created from the Web Service wsdl file will then generate a
(SoapException se) on the client side that you can trap as:

try{
   your code...
}
catch(SoapException se){
   your code...
}
catch(Exception e){
   your code...
}

Make sure you put the catch(SoapException se) before the catch(Exception e)
as Exception will catch all generic and subclassed exceptions (including
SoapException).

> > Its not in the SOAP spec for the InnerException property to be returned.
> > You will have to implement a custom solution.  I did this and it works
[quoted text clipped - 67 lines]
> > >
> > > /Henke

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.