InnerException doesn't work with SoapException

Discussion in 'ASP .Net Web Services' started by Henke, Sep 12, 2003.

  1. Henke

    Henke Guest

    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
     
    Henke, Sep 12, 2003
    #1
    1. Advertising

  2. Henke

    Eirik M. Guest

    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.

    "Henke" <> wrote in message
    news:%...
    > 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., Sep 12, 2003
    #2
    1. Advertising

  3. Henke

    CSharpTooth Guest

    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.


    --------------------------------------------------------
    "Henke" <> wrote in message
    news:#...
    > 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
    >
    >
     
    CSharpTooth, Sep 16, 2003
    #3
  4. Henke

    Eirik M. Guest

    "CSharpTooth" <> wrote in message
    news:...
    > 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
    > 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.
    >
    >
    > --------------------------------------------------------
    > "Henke" <> wrote in message
    > news:#...
    > > 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., Sep 17, 2003
    #4
  5. Henke

    CSharpTooth Guest

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


    "Eirik M." <eirik_at_stockpoint_dot_no> wrote in message
    news:#$...
    >
    > "CSharpTooth" <> wrote in message
    > news:...
    > > 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
    > > 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.
    > >
    > >
    > > --------------------------------------------------------
    > > "Henke" <> wrote in message
    > > news:#...
    > > > 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
    > > >
    > > >

    > >
    > >

    >
    >
     
    CSharpTooth, Sep 21, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Flare

    Inherit from soapException

    Flare, Oct 23, 2003, in forum: ASP .Net
    Replies:
    9
    Views:
    2,394
    Kevin Spencer
    Oct 24, 2003
  2. Marty McDonald

    SoapException - unusual behavior

    Marty McDonald, May 17, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    696
    Marty McDonald
    May 19, 2004
  3. =?Utf-8?B?RGFueQ==?=
    Replies:
    3
    Views:
    700
    =?Utf-8?B?RGFueQ==?=
    Dec 3, 2004
  4. djmc
    Replies:
    1
    Views:
    2,032
  5. Jerry Q

    SOAPException and Browser

    Jerry Q, Jan 16, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    333
    Jerry Q
    Jan 16, 2006
Loading...

Share This Page