Read a XML in web service
-
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. -
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.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!
-
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.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
-
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!
:thumbsup:
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
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