InnerException doesn't work with SoapException

H

Henke

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
 
E

Eirik M.

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.
 
C

CSharpTooth

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.
 
E

Eirik M.

CSharpTooth said:
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.
 
C

CSharpTooth

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top