Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Errorhandling in Webservices

Errorhandling in Webservices

Scheduled Pinned Locked Moved Web Development
helpsysadminxmlquestionannouncement
10 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    matthias s 0
    wrote on last edited by
    #1

    hey, i've got a webservice with one webmethod. if an exception occurs in this method, i'd like to throw it (and transport it back to the client) as a SoapException. my code looks somewhat like this:

    [WebMethod]
    public News[] GetLatestNews(string subscriberKey, int count, string languageName)
    {
    try {
    // do something that throws an exception
    }
    catch (Exception ex)
    {
    string msg = "Internal Server Error: " + ex.Message;
    string actor = HttpContext.Current.Request.Url.AbsoluteUri;
    XmlNode details = BuildDetails(actor, ERR_SERVERERROR, msg);

    throw new SoapException(msg, SoapException.ServerFaultCode, actor, details);
    }
    }

    the method BuildDetails creates an XmlNode with some error information (as you can probably guess by looking at the signature). my problem is: when i start debugging the webservice, the page i get when i invoke the method shows only the error message. without any xml around it. but i'd like to have a proper xml-return which contains all of the information i've placed into the SoapException. what am I missing here? thanks in advance.

    /matthias

    I love deadlines. I like the whooshing sound they make as they fly by.
    [Douglas Adams]

    K 2 Replies Last reply
    0
    • M matthias s 0

      hey, i've got a webservice with one webmethod. if an exception occurs in this method, i'd like to throw it (and transport it back to the client) as a SoapException. my code looks somewhat like this:

      [WebMethod]
      public News[] GetLatestNews(string subscriberKey, int count, string languageName)
      {
      try {
      // do something that throws an exception
      }
      catch (Exception ex)
      {
      string msg = "Internal Server Error: " + ex.Message;
      string actor = HttpContext.Current.Request.Url.AbsoluteUri;
      XmlNode details = BuildDetails(actor, ERR_SERVERERROR, msg);

      throw new SoapException(msg, SoapException.ServerFaultCode, actor, details);
      }
      }

      the method BuildDetails creates an XmlNode with some error information (as you can probably guess by looking at the signature). my problem is: when i start debugging the webservice, the page i get when i invoke the method shows only the error message. without any xml around it. but i'd like to have a proper xml-return which contains all of the information i've placed into the SoapException. what am I missing here? thanks in advance.

      /matthias

      I love deadlines. I like the whooshing sound they make as they fly by.
      [Douglas Adams]

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      I haven't used a soapException before, but often in my webservices I pass out a ref string error. If it is not blank then I got an error. That seems to have worked pretty good for me. Ben

      1 Reply Last reply
      0
      • M matthias s 0

        hey, i've got a webservice with one webmethod. if an exception occurs in this method, i'd like to throw it (and transport it back to the client) as a SoapException. my code looks somewhat like this:

        [WebMethod]
        public News[] GetLatestNews(string subscriberKey, int count, string languageName)
        {
        try {
        // do something that throws an exception
        }
        catch (Exception ex)
        {
        string msg = "Internal Server Error: " + ex.Message;
        string actor = HttpContext.Current.Request.Url.AbsoluteUri;
        XmlNode details = BuildDetails(actor, ERR_SERVERERROR, msg);

        throw new SoapException(msg, SoapException.ServerFaultCode, actor, details);
        }
        }

        the method BuildDetails creates an XmlNode with some error information (as you can probably guess by looking at the signature). my problem is: when i start debugging the webservice, the page i get when i invoke the method shows only the error message. without any xml around it. but i'd like to have a proper xml-return which contains all of the information i've placed into the SoapException. what am I missing here? thanks in advance.

        /matthias

        I love deadlines. I like the whooshing sound they make as they fly by.
        [Douglas Adams]

        K Offline
        K Offline
        kubben
        wrote on last edited by
        #3

        Looks at the documentation, like I said before I haven't used soapexception. It seems that the xml is only there if you put it there.

        public class ThrowSoapException : WebService
        {
        // This XML Web service method generates a SOAP Client Fault code
        [WebMethod]
        public void myThrow(){

            // Build the detail element of the SOAP fault.
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            System.Xml.XmlNode node = doc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace);
        
        
            // Build specific details for the SoapException.
            // Add first child of detail XML element.
            System.Xml.XmlNode details = doc.CreateNode(XmlNodeType.Element, "mySpecialInfo1", "http://tempuri.org/");
            System.Xml.XmlNode detailsChild = doc.CreateNode(XmlNodeType.Element, "childOfSpecialInfo", "http://tempuri.org/");
            details.AppendChild(detailsChild);
        
                
            // Add second child of detail XML element with an attribute.
            System.Xml.XmlNode details2 = doc.CreateNode(XmlNodeType.Element, "mySpecialInfo2", "http://tempuri.org/");
            XmlAttribute attr = doc.CreateAttribute("t", "attrName", "http://tempuri.org/");
            attr.Value = "attrValue";
            details2.Attributes.Append(attr);
        
            // Append the two child elements to the detail node.
            node.AppendChild(details);
            node.AppendChild(details2);
        
                
            //Throw the exception.    
            SoapException se = new SoapException("Fault occurred", SoapException.ClientFaultCode,Context.Request.Url.AbsoluteUri,node);
        
            throw se;
            return;    }
        

        }

        Ben

        M 1 Reply Last reply
        0
        • K kubben

          Looks at the documentation, like I said before I haven't used soapexception. It seems that the xml is only there if you put it there.

          public class ThrowSoapException : WebService
          {
          // This XML Web service method generates a SOAP Client Fault code
          [WebMethod]
          public void myThrow(){

              // Build the detail element of the SOAP fault.
              System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
              System.Xml.XmlNode node = doc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace);
          
          
              // Build specific details for the SoapException.
              // Add first child of detail XML element.
              System.Xml.XmlNode details = doc.CreateNode(XmlNodeType.Element, "mySpecialInfo1", "http://tempuri.org/");
              System.Xml.XmlNode detailsChild = doc.CreateNode(XmlNodeType.Element, "childOfSpecialInfo", "http://tempuri.org/");
              details.AppendChild(detailsChild);
          
                  
              // Add second child of detail XML element with an attribute.
              System.Xml.XmlNode details2 = doc.CreateNode(XmlNodeType.Element, "mySpecialInfo2", "http://tempuri.org/");
              XmlAttribute attr = doc.CreateAttribute("t", "attrName", "http://tempuri.org/");
              attr.Value = "attrValue";
              details2.Attributes.Append(attr);
          
              // Append the two child elements to the detail node.
              node.AppendChild(details);
              node.AppendChild(details2);
          
                  
              //Throw the exception.    
              SoapException se = new SoapException("Fault occurred", SoapException.ClientFaultCode,Context.Request.Url.AbsoluteUri,node);
          
              throw se;
              return;    }
          

          }

          Ben

          M Offline
          M Offline
          matthias s 0
          wrote on last edited by
          #4

          hey kubben, thanks for your reply. yes, i knew this already. but i've copy-pasted your code above into my project, just in case i missed something. the same result. the only return i get is the literal: "Fault occurred". i need to return a properly formatted soap response with a couple of details concerning the error? i was already wondering, if IE is "eating" the soap message and reducing it to this simple string. but it seems my IE settings are ok. kind regards

          /matthias

          I love deadlines. I like the whooshing sound they make as they fly by.
          [Douglas Adams]

          K 1 Reply Last reply
          0
          • M matthias s 0

            hey kubben, thanks for your reply. yes, i knew this already. but i've copy-pasted your code above into my project, just in case i missed something. the same result. the only return i get is the literal: "Fault occurred". i need to return a properly formatted soap response with a couple of details concerning the error? i was already wondering, if IE is "eating" the soap message and reducing it to this simple string. but it seems my IE settings are ok. kind regards

            /matthias

            I love deadlines. I like the whooshing sound they make as they fly by.
            [Douglas Adams]

            K Offline
            K Offline
            kubben
            wrote on last edited by
            #5

            You know looking at the overloads for the create of the soapException, I can find one that matches what you are passing in. I am thinking perhaps that is the problem? The only overloads with four parameters are:

            public SoapException (
            string message,
            XmlQualifiedName code,
            string actor,
            XmlNode detail
            )
            public SoapException (
            string message,
            XmlQualifiedName code,
            string actor,
            Exception innerException
            )

            So I think that is where you need to look. Ben

            M 1 Reply Last reply
            0
            • K kubben

              You know looking at the overloads for the create of the soapException, I can find one that matches what you are passing in. I am thinking perhaps that is the problem? The only overloads with four parameters are:

              public SoapException (
              string message,
              XmlQualifiedName code,
              string actor,
              XmlNode detail
              )
              public SoapException (
              string message,
              XmlQualifiedName code,
              string actor,
              Exception innerException
              )

              So I think that is where you need to look. Ben

              M Offline
              M Offline
              matthias s 0
              wrote on last edited by
              #6

              but the first one matches the code i've posted:

              throw new SoapException(msg, SoapException.ServerFaultCode, actor, details);

              regards, matthias

              /matthias

              I love deadlines. I like the whooshing sound they make as they fly by.
              [Douglas Adams]

              K 3 Replies Last reply
              0
              • M matthias s 0

                but the first one matches the code i've posted:

                throw new SoapException(msg, SoapException.ServerFaultCode, actor, details);

                regards, matthias

                /matthias

                I love deadlines. I like the whooshing sound they make as they fly by.
                [Douglas Adams]

                K Offline
                K Offline
                kubben
                wrote on last edited by
                #7

                I think that SoapException.ServerFaulCode is not a XmlQualifiedName. An XML qualified name is a namespace qualified local name in the format of namespace:localname. Because prefixes are only required when XML is persisted or read, they are irrelevant for XmlQualifiedName objects. This class assumes that prefixes are irrelevant. It is the responsibility of the user to ensure the local name does not contain a ":". Ben

                1 Reply Last reply
                0
                • M matthias s 0

                  but the first one matches the code i've posted:

                  throw new SoapException(msg, SoapException.ServerFaultCode, actor, details);

                  regards, matthias

                  /matthias

                  I love deadlines. I like the whooshing sound they make as they fly by.
                  [Douglas Adams]

                  K Offline
                  K Offline
                  kubben
                  wrote on last edited by
                  #8

                  Then again, I am wrong. Sorry about that. Ben

                  1 Reply Last reply
                  0
                  • M matthias s 0

                    but the first one matches the code i've posted:

                    throw new SoapException(msg, SoapException.ServerFaultCode, actor, details);

                    regards, matthias

                    /matthias

                    I love deadlines. I like the whooshing sound they make as they fly by.
                    [Douglas Adams]

                    K Offline
                    K Offline
                    kubben
                    wrote on last edited by
                    #9

                    I found this link: http://www.developer.com/net/csharp/article.php/10918_3088231_1[^] The only real different between what that article has seems to be the uri they are passing in. Anyway, sorry I haven't been much help. Ben

                    M 1 Reply Last reply
                    0
                    • K kubben

                      I found this link: http://www.developer.com/net/csharp/article.php/10918_3088231_1[^] The only real different between what that article has seems to be the uri they are passing in. Anyway, sorry I haven't been much help. Ben

                      M Offline
                      M Offline
                      matthias s 0
                      wrote on last edited by
                      #10

                      don't worry about not solving the issue. it's the will that counts. ;) i'll look into the article, thanks! kind regards.

                      /matthias

                      I love deadlines. I like the whooshing sound they make as they fly by.
                      [Douglas Adams]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups