???? ID: 330600 - ????? ???????: 29 ??????? 2010 - ??????: 4.0

HOW TO: Use XmlDocument Elements When Passed to or Returned from WebMethods by Using Visual C# .NET

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.

?? ????? ??

??? ?? ??????? ???? | ??? ?? ??????? ????
This article refers to the following Microsoft .NET Framework Class Library namespaces:
  • System.Xml

??????

This step-by-step article describes how to write code in .NET applications to execute Web Service methods that take anXmlDocumentparameter, or that return anXmlDocument???????? ???

?????

WhenXmlDocumentobjects are passed as parameters to Web Service methods, or are returned from Web Service methods, they are marshaled asXmlNodeobjects. TheXmlDocument, ??XmlNode?????? ??? ???? ???? ??? ???System.Xml??? ????? (XmlDocument?? ???XmlNode).

??? ???? ?? ??? ??? marshaled manipulation ??XmlNode(?? ??? ???? ?? ???? ???? ?? ??? ???? ??? ??, ?? ??? ???? ?? ???? ???? ?? ?????? ???? ??? ??) XmlDocument API ?? ????? ???? ?? ????? ????? ?? ???????? ??XmlNode?????? ?? ???, ???? ?????? ???? ??? ??? ??XmlDocument???????? ??? ??? ???? ?? ???, ????? ??? ?? ???? ?? ???? ????::
  • XmlDocument.LoadXml(XmlNode.OuterXml)
  • XmlDocument.ImportNode(XmlNode, true)
?? ???? ??? ????? demonstrate ?? ??????? ?? ????? ???? ????

??? ??? ???? ?????

  1. Microsoft Visual Studio .NET, ??? ????? ??? ??? ????? C# .NET asp.NET ??? ???? ?????????? ??? ???? ?? ???, ????? ????? ?? ???? ????::
    1. ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????.
    2. ?????????????? ??????????, ????? ????????? C# ??????????? ????-????? ????, ?? ???? ???ASP.NET ??? ?????????????????????
  2. ????????????? ????? ???, ??????XMLDocService(???????? ??? ?? WebService1) ??????? ??? ????????? ?????
  3. ???? ?? ??? Service1.asmx ?? ???? ?? ??????? ??? ???? ?? ??? ?????XMLDocService.asmx.
  4. ????? ????,??? ????? ?? ????? ???? ?? ??? ???? ????? ??????? ????? ?? ????? ???? ?? ??? ??????? ????????
  5. ???? ?? ?? ???? ???? ?? ????????? ???XMLDocument???????? ??? ???? ?????? ???? ?? ???????? ???? ?? ??? ????????? ?? ?????? ???WebMethod??????? ??? ?? ??????? ?? ???? ???? ???? ???? ?????? ??????

    ???:???????? ???? ???? ???? ?????WebMethod??????? ??? ????????? ??? ???? ??????? ?? ??? ?? ??? ??????????? ????? ?? ?????? ?? ??? ?? ??????? ?? ????? ???? ?? ???? ?? ???WebService???? ??????? ????????? ??? ????? ???? ???? ??? ?????? ??? ??????? ????????? ???? ?? ????????? ????, ???? ?? ????? ?? ???? ???WebMethod??????? ?????? ??? ?? XML ??? ?? ??? ??? ????? ????? ?? ???? ?????
  6. ???? ?? ??? ????? ??? ???? ??????? ??????XMLDocService???? ???? ???? ??? ????? ??:
    [WebMethod]
    public 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 );
    }
    [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;
    }
  7. ????? ????????????? ??,??????? ????????? ???? ????? ???
  8. XML ??? ???? ?? ??????? ???? ?? ??? XMLDocService.asmx XML ??? ???? ????? ?????? ??? ?? ?? ????? ?? ????? ???? ?? ??? ??????? ???????? ??? ??, URL ?? http://localhost/XMLDocService/XMLDocService.asmx. Microsoft asp.NET ?????? ???? ???? XML ??? ???? ??? ????? XML ??? ?? ????? ???? ?? ?? ????? ?? XML ??? ???? ?? ??????? ??????? ?? ??????? ???? ?? ??? ?? ????? ?? ????? ?? ?? ???? ????

??? ???? ?? ??? ?? ???? ??

  1. Visual Studio .NET, ??? ????? ???????????? ????????????, ?? ???? ????????????.
  2. ?????????????? ??????????, ????? ????????? C# ??????????? ????-????? ????, ?? ???? ???????? ??????????????????????????
  3. ?? ????????? ??? ?????? ?? ??? ??? ??????XMLDocService??? ?????

    ?? ??? ?? ??????? ???????? ?? ?? ???????? ???? ????? ??? ???????? ???? ????? ??, ?? ??? ???????? ???? ?? ?????? ??? ???? ???? ???????? ???? ??? ??? ?? ???????? ?? ??? ?? ?? ?? ???? ?????????? ?????? ?????????? (URI) ?? ??? ??? ???? ?? SOAP ?????? ?? ??? ????
    1. ????? ????????????????? ??,?????? ??? ??????.
    2. ???????? ?????? ??????????? ????? ???, ??? ???? ??? ?? URL ??????????? ????? ???, ?? ???? ??? ENTER ?????? ??? ?? ??? ???? ?? ????? ???? ?? ??? ??????? ???????? ???, URL ?? http://localhost/XMLDocService/XMLDocService.asmx.
    3. ????? ????,?????? ??????. ???????? ??? ??, ?? ?? ???? ??? (XMLDocService.vsdisco) ??? ????? ?? URL ????? ?? ????? ??????????? ??? ????? ?? ??? ?????????? ??? ??? XMLDocService ???? ?? ???? ?? ??? ???? ?? ????
    4. ??????? ??????? ???????????? ?? ?????? Explorer ?? ??? ?? ????? ???? ??? ????? ??? ?????
  4. ?? ??? ???????? ???????? ?? ??????? ?????XMLDocService??? ????? ??? ????? ??? ?????????????????? ?? ??? ???? ???.:
    localhost.XMLDocService myXMLDocService = new localhost.XmlDocService();
  5. ???????? ???????? ?? ?????? ??????? ????, ????? ??? ?? ????? ????:
    XmlDocument myXmlDocumentObject = myXMLDocService.GetXmlDocument();
  6. ????? ????????????? ??,??????? ??????????? ????????? ????? ???
  7. ?? ????? ????? ?????? ????? ??????? ???? ??:
    ?????? 'System.Xml.XmlNode' ?? ??? ' System.Xml.XmlDocument' implicitly ?????? ???? ?? ????
  8. ???? invocation ?? ????? ?? ???????????? ????:
    XmlNode myXMLNodeObject = myXMLDocService.GetXmlDocument();
  9. ????? ????????????? ??,??????? ??????????? ????????? ????? ??? ?? ????????? ??????????? ??? ???? ????
  10. ???? ?? ??? ??? ??? ????XmlNode??? ???XmlDocument?? ????? ?? ???????? ????ImportNode????:
    XmlDocument myXmlDocumentObject = new XmlDocument();
    myXmlDocumentObject.AppendChild(myXmlDocumentObject.ImportNode(myXMLNodeObject,true));
  11. ?? ???? ?? ????? ??? ???? ?? ?? ??? ???? ?????? ?? ??? ????:
    string strFirstName = WebServiceObject.GetFirstName( XmlDocumentObject );
  12. ???? ?? ????? ??? ????? ?? ??????? ????:
    Console.WriteLine( "The first name of the author is: " +strFirstName );
  13. ????? ????????????? ??,??????? ??????????? ????????? ????? ???
  14. ????? ???????? ???????? ??,?????????? ????????? ??????

?????? ??????

??? ?? ????? ???? ?? ?? ??? ???? ?????? ?? ????? ??? ??XmlDocument???? ????????XmlDocument???????? ??????? ????????? ??? ???? ????? ????? ?????? ????? ??????? ???? ??:
Implicitly ?????? ???? ???? ?? ??? 'System.Xml.XmlDocument' ' System.Xml.XmlNode' ?????
?????? ?? ???? ?? ??????? Microsoft .NET ??? ???? casting ?? ?????? ???? ??? ??XmlDocument?? ??? ??? marshaled ??XmlNode. ????? ???? ??XmlNode???????? ?? ??XmlDocument??????? ????????XmlDocument?? ??????? ?? ?? ??XmlNode.

??? ???, ??????? ???? ?? ???XmlDocument???????? ?? ???, ???? ?????? ????????? ?????????? ?? ??? ???XmlNode???????? ??? ??? ?? ???????? ?? ??? ??? ?????XmlDocument, ???? ????? ????? ?????? ????? ??????? ???? ??:
????????? cast ????? ???? ??
????? ?? ???? ?? ???????XmlDocument?? ???? ?? ?? ??????? ?? ??? ??? marshaled ?? ??XmlNode????? ???? ?? ??? ??? ?? ????? ???? ?? ??XmlNode???????? ?? ??XmlDocument???????? ???????? (???? casting .NET ??? ?????? ???? ??)?

??????

??? ?????? ????? ?? ??? ???? ???? ?? ???? ??? ???????? ??????? ?? ??? Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
308359  (http://support.microsoft.com/kb/308359/EN-US/ ) TO HOW: ????? C# .NET ?? ????? ?? ?? ?????? ??? ???? ?????

???? ???? ???? ??:
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Web Services Enhancements for Microsoft .NET 1.1
  • Microsoft .NET Framework 1.0
  • Microsoft .NET Framework 1.1
??????: 
kbclient kbhowtomaster kbhowto kbmt KB330600 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:330600  (http://support.microsoft.com/kb/330600/en-us/ )