catch Custom SoapException

Discussion in 'ASP .Net' started by Giulio, Jun 6, 2006.

  1. Giulio

    Giulio Guest

    Hi programmers, I'm quite new in this blog, I have a question
    concerning web services Soap Exceptions: I created a class
    MySoapException derived from SoapException, I add the references both
    server-side and client-side, and I tried to implement correctly
    serialization, I mean, the "ability" of a class to be used through a
    web services communication (that's not so correct, I hope you
    understand what I mean).
    Here is my class:

    [Serializable]
    public class MySoapException : SoapException, ISerializable
    {
    //private string tipoecc;

    public MySoapException() : base()
    {
    //
    // TODO: Add constructor logic here
    //

    }
    public MySoapException(SerializationInfo si, StreamingContext
    sc) : base(si,sc)

    {

    }

    public string Tipoecc
    {
    get { return tipoecc; }
    set { tipoecc = value; }
    }

    public override void GetObjectData(SerializationInfo si,
    StreamingContext sc)
    {

    base.GetObjectData(si, sc);

    si.AddValue("Tipoecc", tipoecc);

    }


    }

    In this way, the new Property Tipoecc shoud be understood and
    deserializad correctly by the (soap) client.
    The web service throw the customized SoapException in this way:

    MySoapException myexc = new MySoapException();
    myexc.Tipoecc = "1";
    throw myexc;

    I set the value of TipoEcc = "1".
    The following code is client-side:

    catch (MySoapException mse)
    {

    //nel caso sincrono l'eccezione non è contenuta
    nel campo InnerException

    //la proprietà Tipoecc indica il valore custom con
    cui è definita l'eccezione
    string msg;
    msg = mse.Message;
    msg += "\nTipo eccezione: " +
    mse.GetType().ToString();
    //msg += "\nValore eccezione: " +
    mse.Tipoecc.ToString();
    MessageBox.Show(msg);

    }

    I think it should catch the custom exception, because I add the same
    reference to the dll containing the implementation of the class
    MySoapException.
    But... it doesn't work!!!
    The client catches the Exception ONLY as SoapException, and nothing
    else.
    I know there is another pretty way to pass custom fields or attributes
    by appending a new XMLNode to the Detail property of a SoapException,
    and it also works good... But I would like to know WHERE is my mistake
    (or my mistakes...).
    Thanks a lot.
    Giulio
     
    Giulio, Jun 6, 2006
    #1
    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. John Harkin
    Replies:
    0
    Views:
    151
    John Harkin
    Aug 18, 2004
  2. Doug
    Replies:
    0
    Views:
    97
  3. Paul Cowan

    Custom Soapexception

    Paul Cowan, Oct 20, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    166
  4. Ghislain Tanguay
    Replies:
    1
    Views:
    139
    Dilip Krishnan
    Jan 28, 2005
  5. Giulio

    Catch Custom SoapException

    Giulio, Jun 6, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    111
    Giulio
    Jun 6, 2006
Loading...

Share This Page