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. General Programming
  3. C#
  4. Read a XML in web service

Read a XML in web service

Scheduled Pinned Locked Moved C#
xmlhelplearning
5 Posts 4 Posters 0 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.
  • A Offline
    A Offline
    abbd
    wrote on last edited by
    #1

    hello, I would use my web service to get a XML file, i try for : My web service : public class Service1 : System.Web.Services.WebService { [WebMethod] public string GetFirstName(XmlNode XmlNodePassed) { // Create a new XmLDocument object. XmlDocument XmlDocumentObject = new XmlDocument(); // Load the XmlNode into the XmlDocument object. XmlDocumentObject.LoadXml(XmlNodePassed.OuterXml); // Find the first name of the author. XmlNodeList XmlNodeListObj = XmlDocumentObject.GetElementsByTagName("first-name"); // Return the first name. return XmlNodeListObj[0].ChildNodes[0].Value; } } i would consumme a service as : public static XmlDocument GetXmlDocument() { // Create an XmlDocument object. XmlDocument xmlDocumentObject = new XmlDocument(); xmlDocumentObject.LoadXml("<book genre=\"novel\" publicationdate=\"1997\" " + " ISBN=\"1-861001-57-5\">" + " <title>Pride And Prejudice</title>" + " <author>" + " <first-name>Jane</first-name>" + " <last-name>Austen</last-name>" + " </author>" + " <price>24.95</price>" + "</book>"); // Return the created XmlDocument object. return (xmlDocumentObject); } static void Main(string[] args) { XmlDocument xml = GetXmlDocument(); ServiceReference1.Service1SoapClient rr = new ConsoleApplication1.ServiceReference1.Service1SoapClient(); string gg = rr.GetFirstName(XmlDocumentObject); } Unfortunatly, i have an error : cant convert XMLdocument to XMLElment. Thank you verry mutch.

    H D 2 Replies Last reply
    0
    • A abbd

      hello, I would use my web service to get a XML file, i try for : My web service : public class Service1 : System.Web.Services.WebService { [WebMethod] public string GetFirstName(XmlNode XmlNodePassed) { // Create a new XmLDocument object. XmlDocument XmlDocumentObject = new XmlDocument(); // Load the XmlNode into the XmlDocument object. XmlDocumentObject.LoadXml(XmlNodePassed.OuterXml); // Find the first name of the author. XmlNodeList XmlNodeListObj = XmlDocumentObject.GetElementsByTagName("first-name"); // Return the first name. return XmlNodeListObj[0].ChildNodes[0].Value; } } i would consumme a service as : public static XmlDocument GetXmlDocument() { // Create an XmlDocument object. XmlDocument xmlDocumentObject = new XmlDocument(); xmlDocumentObject.LoadXml("<book genre=\"novel\" publicationdate=\"1997\" " + " ISBN=\"1-861001-57-5\">" + " <title>Pride And Prejudice</title>" + " <author>" + " <first-name>Jane</first-name>" + " <last-name>Austen</last-name>" + " </author>" + " <price>24.95</price>" + "</book>"); // Return the created XmlDocument object. return (xmlDocumentObject); } static void Main(string[] args) { XmlDocument xml = GetXmlDocument(); ServiceReference1.Service1SoapClient rr = new ConsoleApplication1.ServiceReference1.Service1SoapClient(); string gg = rr.GetFirstName(XmlDocumentObject); } Unfortunatly, i have an error : cant convert XMLdocument to XMLElment. Thank you verry mutch.

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      You have been around CP long enough now to know the correct way to format code snippets in your questions. For goodness sake use <pre>your code goes here</pre> tags. It doesn't matter if you think the way you do it is prettier or whatever the reason is. Do you not realize that red/blue colour blindness is the most common form. You are actually making it harder for people to help you.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” I wouldn't let CG touch my Abacus!

      OriginalGriffO 1 Reply Last reply
      0
      • A abbd

        hello, I would use my web service to get a XML file, i try for : My web service : public class Service1 : System.Web.Services.WebService { [WebMethod] public string GetFirstName(XmlNode XmlNodePassed) { // Create a new XmLDocument object. XmlDocument XmlDocumentObject = new XmlDocument(); // Load the XmlNode into the XmlDocument object. XmlDocumentObject.LoadXml(XmlNodePassed.OuterXml); // Find the first name of the author. XmlNodeList XmlNodeListObj = XmlDocumentObject.GetElementsByTagName("first-name"); // Return the first name. return XmlNodeListObj[0].ChildNodes[0].Value; } } i would consumme a service as : public static XmlDocument GetXmlDocument() { // Create an XmlDocument object. XmlDocument xmlDocumentObject = new XmlDocument(); xmlDocumentObject.LoadXml("<book genre=\"novel\" publicationdate=\"1997\" " + " ISBN=\"1-861001-57-5\">" + " <title>Pride And Prejudice</title>" + " <author>" + " <first-name>Jane</first-name>" + " <last-name>Austen</last-name>" + " </author>" + " <price>24.95</price>" + "</book>"); // Return the created XmlDocument object. return (xmlDocumentObject); } static void Main(string[] args) { XmlDocument xml = GetXmlDocument(); ServiceReference1.Service1SoapClient rr = new ConsoleApplication1.ServiceReference1.Service1SoapClient(); string gg = rr.GetFirstName(XmlDocumentObject); } Unfortunatly, i have an error : cant convert XMLdocument to XMLElment. Thank you verry mutch.

        D Offline
        D Offline
        Dan Mos
        wrote on last edited by
        #3

        First of all :thumbsup: for Henry's sugestion. Second of all is pretty clear(actually not) what happend. In the Main method you call GetFirstName() but you pass a xml document instead of a XMLNode. It can't convert from xmlDoc to xmlElem/Node. Also inside Main there is no XmlDocumentObject declaration/creation just xml in the line:

        XmlDocument xml = GetXmlDocument();

        All the best, Dan

        A 1 Reply Last reply
        0
        • H Henry Minute

          You have been around CP long enough now to know the correct way to format code snippets in your questions. For goodness sake use <pre>your code goes here</pre> tags. It doesn't matter if you think the way you do it is prettier or whatever the reason is. Do you not realize that red/blue colour blindness is the most common form. You are actually making it harder for people to help you.

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” I wouldn't let CG touch my Abacus!

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          :thumbsup:

          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • D Dan Mos

            First of all :thumbsup: for Henry's sugestion. Second of all is pretty clear(actually not) what happend. In the Main method you call GetFirstName() but you pass a xml document instead of a XMLNode. It can't convert from xmlDoc to xmlElem/Node. Also inside Main there is no XmlDocumentObject declaration/creation just xml in the line:

            XmlDocument xml = GetXmlDocument();

            All the best, Dan

            A Offline
            A Offline
            abbd
            wrote on last edited by
            #5

            Hello, Thank you verry mutch for your answer, so, i replace the input parameters and i set public static XmlDocument GetXmlDocument(), and i have the same probleme, thank you verry mutch.

            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