Define Correspond Fault for the Soap Exception in the WSDL

Discussion in 'ASP .Net Web Services' started by huohaodian@gmail.com, Aug 5, 2008.

  1. Guest

    Hi,

    I am planning to use a custom wsdl for my web service, it seems
    that the SoapException class provides nice and easy way to handle soap
    exception on the server side. Corresponding to the associated fault
    definition in the wsdl, how should I define the fault element that
    corresponds to the exception SoapException may be raised from server
    with message, code, actor and detail?

    Thanks in advance.
     
    , Aug 5, 2008
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > Hi,
    >
    > I am planning to use a custom wsdl for my web service, it seems
    > that the SoapException class provides nice and easy way to handle soap
    > exception on the server side. Corresponding to the associated fault
    > definition in the wsdl, how should I define the fault element that
    > corresponds to the exception SoapException may be raised from server
    > with message, code, actor and detail?


    You simply define the structure of the detail section using XML Schema.
    Then, refer to it in the <wsdl:message> element that defines the fault
    message. Refer to the fault message in the <wsdl:fault> section using the
    type attribute.

    Then, all you have to do is construct an instance of your fault detail and
    provide it to the SoapException constructor.

    I don't have time to find or create an example today, but let me know if
    you're still stuck after this and I'll try to make time.

    --
    John Saunders | MVP - Connected System Developer
     
    John Saunders, Aug 5, 2008
    #2
    1. Advertising

  3. Guest

    On Aug 5, 4:01 pm, "John Saunders" <> wrote:
    > <> wrote in message
    >
    > news:...
    >
    > > Hi,

    >
    > >   I am planning to use a custom wsdl for my web service, it seems
    > > that the SoapException class provides nice and easy way to handle soap
    > > exception on the server side. Corresponding to the associated fault
    > > definition in the wsdl, how should I define the fault element that
    > > corresponds to the exception SoapException may be raised from server
    > > with message, code, actor and detail?

    >
    > You simply define the structure of the detail section using XML Schema.
    > Then, refer to it in the <wsdl:message> element that defines the fault
    > message. Refer to the fault message in the <wsdl:fault> section using the
    > type attribute.
    >
    > Then, all you have to do is construct an instance of your fault detail and
    > provide it to the SoapException constructor.
    >
    > I don't have time to find or create an example today, but let me know if
    > you're still stuck after this and I'll try to make time.
    >
    > --
    > John Saunders | MVP - Connected System Developer



    Thank you so much John.

    I am still struggling... is it possible you could give me a little
    sample?

    Thanks again.
     
    , Aug 6, 2008
    #3
  4. Guest

    On Aug 5, 4:01 pm, "John Saunders" <> wrote:
    > <> wrote in message
    >
    > news:...
    >
    > > Hi,

    >
    > >   I am planning to use a custom wsdl for my web service, it seems
    > > that the SoapException class provides nice and easy way to handle soap
    > > exception on the server side. Corresponding to the associated fault
    > > definition in the wsdl, how should I define the fault element that
    > > corresponds to the exception SoapException may be raised from server
    > > with message, code, actor and detail?

    >
    > You simply define the structure of the detail section using XML Schema.
    > Then, refer to it in the <wsdl:message> element that defines the fault
    > message. Refer to the fault message in the <wsdl:fault> section using the
    > type attribute.
    >
    > Then, all you have to do is construct an instance of your fault detail and
    > provide it to the SoapException constructor.
    >
    > I don't have time to find or create an example today, but let me know if
    > you're still stuck after this and I'll try to make time.
    >
    > --
    > John Saunders | MVP - Connected System Developer


    I have created structure for the detail section

    <s:complexType name="detail">
    <s:sequence>
    <s:element name="ErrorCode" type="s:int"/>
    <s:element name="Message" type="s:string"/>
    </s:sequence>
    </s:complexType>

    then added a message
    <wsdl:message name="FaultError" type="tns:detail"/>

    then added fault to the operation
    <wsdl:fault name="FaultName" message="tns:FaultError"/>

    and then after adding <soap12:fault name="FaultName" use="literal"/>
    in the soap 12 section, the editor stopped to complain.

    On the server side, I follow the sample to raise the exception with
    something like
    XmlDocument doc = new XmlDocument();
    XmlNode detail = doc.CreateNode(XmlNodeType.Element,
    SoapException.DetailElementName.Name,
    SoapException.DetailElementName.Namespace);

    XmlNode errorType = doc.CreateNode(XmlNodeType.Element,
    "ErrorCode", myNS);
    errorType.InnerText = "-1";

    XmlNode lineNum = doc.CreateNode(XmlNodeType.Element,
    "Message", myNS);
    lineNum.InnerText = "Error";


    detail.AppendChild(errorType);
    detail.AppendChild(lineNum);


    string errorMsg = "An error was received while processing the
    message (see Detail element for more information)";
    SoapException exc = new SoapException(errorMsg,
    SoapException.ClientFaultCode, "", detail);
    throw exc;

    Anything I should pay attention on the "Fault Name" in the <wsdl:fault
    name="FaultName" message="tns:FaultError"/>?
    What is the correspondence between soap exception details and this
    FaultName?

    Thanks in advance.
     
    , Aug 7, 2008
    #4
  5. Todd Guest

    Was there any examples posted for this? I have the same issue.

    Thanks in advance

    "" wrote:

    > On Aug 5, 4:01 pm, "John Saunders" <> wrote:
    > > <> wrote in message
    > >
    > > news:...
    > >
    > > > Hi,

    > >
    > > > I am planning to use a custom wsdl for my web service, it seems
    > > > that the SoapException class provides nice and easy way to handle soap
    > > > exception on the server side. Corresponding to the associated fault
    > > > definition in the wsdl, how should I define the fault element that
    > > > corresponds to the exception SoapException may be raised from server
    > > > with message, code, actor and detail?

    > >
    > > You simply define the structure of the detail section using XML Schema.
    > > Then, refer to it in the <wsdl:message> element that defines the fault
    > > message. Refer to the fault message in the <wsdl:fault> section using the
    > > type attribute.
    > >
    > > Then, all you have to do is construct an instance of your fault detail and
    > > provide it to the SoapException constructor.
    > >
    > > I don't have time to find or create an example today, but let me know if
    > > you're still stuck after this and I'll try to make time.
    > >
    > > --
    > > John Saunders | MVP - Connected System Developer

    >
    > I have created structure for the detail section
    >
    > <s:complexType name="detail">
    > <s:sequence>
    > <s:element name="ErrorCode" type="s:int"/>
    > <s:element name="Message" type="s:string"/>
    > </s:sequence>
    > </s:complexType>
    >
    > then added a message
    > <wsdl:message name="FaultError" type="tns:detail"/>
    >
    > then added fault to the operation
    > <wsdl:fault name="FaultName" message="tns:FaultError"/>
    >
    > and then after adding <soap12:fault name="FaultName" use="literal"/>
    > in the soap 12 section, the editor stopped to complain.
    >
    > On the server side, I follow the sample to raise the exception with
    > something like
    > XmlDocument doc = new XmlDocument();
    > XmlNode detail = doc.CreateNode(XmlNodeType.Element,
    > SoapException.DetailElementName.Name,
    > SoapException.DetailElementName.Namespace);
    >
    > XmlNode errorType = doc.CreateNode(XmlNodeType.Element,
    > "ErrorCode", myNS);
    > errorType.InnerText = "-1";
    >
    > XmlNode lineNum = doc.CreateNode(XmlNodeType.Element,
    > "Message", myNS);
    > lineNum.InnerText = "Error";
    >
    >
    > detail.AppendChild(errorType);
    > detail.AppendChild(lineNum);
    >
    >
    > string errorMsg = "An error was received while processing the
    > message (see Detail element for more information)";
    > SoapException exc = new SoapException(errorMsg,
    > SoapException.ClientFaultCode, "", detail);
    > throw exc;
    >
    > Anything I should pay attention on the "Fault Name" in the <wsdl:fault
    > name="FaultName" message="tns:FaultError"/>?
    > What is the correspondence between soap exception details and this
    > FaultName?
    >
    > Thanks in advance.
    >
     
    Todd, Sep 10, 2008
    #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. Rob
    Replies:
    0
    Views:
    1,154
  2. Chris Bedford
    Replies:
    0
    Views:
    602
    Chris Bedford
    Aug 21, 2003
  3. Mickey Segal
    Replies:
    1
    Views:
    312
    Thomas Hawtin
    May 19, 2006
  4. Nanda
    Replies:
    2
    Views:
    2,989
    Nanda
    Aug 16, 2009
  5. Emanuele Parati

    soap:fault in WSDL

    Emanuele Parati, Jan 14, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    145
    Emanuele Parati
    Jan 14, 2004
Loading...

Share This Page