2012-04-19 55 views
6

在我的Windows Phone應用程序中我需要使用XmlDocument類。但我仍然得到錯誤Windows Phone - 無法找到XmlDocument

Error 1 The type or namespace name 'XmlDocument' could not be found (are you missing a using directive or an assembly reference?)

我添加引用和 using System.Xml

但它不幫助。

這是我的SOAP示例代碼,我需要修改與的XDocument 編輯工作 - 增加了SOAP示例代碼

public static void CallWebService() 
    { 
     var _url = "http://xxxxxxxxx/Service1.asmx"; 
     var _action = "http://xxxxxxxx/Service1.asmx?op=HelloWorld"; 

     XmlDocument soapEnvelopeXml = CreateSoapEnvelope() 
     HttpWebRequest webRequest = CreateWebRequest(_url, _action); 
     InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest); 

     // begin async call to web request. 
     IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null); 

     // suspend this thread until call is complete. You might want to 
     // do something usefull here like update your UI. 
     asyncResult.AsyncWaitHandle.WaitOne(); 

     // get the response from the completed web request. 
     string soapResult; 
     using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult)) 
     using (StreamReader rd = new StreamReader(webResponse.GetResponseStream())) 
     { 
      soapResult = rd.ReadToEnd(); 
     } 
     Console.Write(soapResult); 
} 


    private static HttpWebRequest CreateWebRequest(string url, string action) 
    { 
     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); 
     webRequest.Headers.Add("SOAPAction", action); 
     webRequest.ContentType = "text/xml;charset=\"utf-8\""; 
     webRequest.Accept = "text/xml"; 
     webRequest.Method = "POST"; 
     return webRequest; 
    } 

    private static XmlDocument CreateSoapEnvelope() 
    { 
     XmlDocument soapEnvelop = new XmlDocument(); 
     soapEnvelop.LoadXml(@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/1999/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/1999/XMLSchema""><SOAP-ENV:Body><HelloWorld xmlns=""http://tempuri.org/"" SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""><int1 xsi:type=""xsd:integer"">12</int1><int2 xsi:type=""xsd:integer"">32</int2></HelloWorld></SOAP-ENV:Body></SOAP-ENV:Envelope>"); 
     return soapEnvelop; 
    } 

    private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest) 
    { 
     using (Stream stream = webRequest.GetRequestStream()) 
     { 
      soapEnvelopeXml.Save(stream); 
     } 
    }` 
+2

爲什麼你不使用Linq到Xml/XDocument來代替? – BrokenGlass 2012-04-19 22:38:07

+0

可能值得檢查:[如何在Windows Phone 7應用程序中使用webservice](http://www.codeproject.com/Questions/355937); [Windows Phone 7 in 7:連接到Web服務](http://msdn.microsoft.com/en-us/gg241261.aspx); [從Windows Phone 7消費ASMX Web服務](http://social.msdn.microsoft.com/Forums/wpapps/en-US/38815099-8394-448c-80bf-a93279fbbdac/); [創建服務參考:無法爲服務引用生成代碼](http://software-development-toolbox.blogspot.ru/2009/02/creating-service-reference-failed-to.html) – GSerg 2014-04-17 17:50:36

回答

0
+1

好的,我得到它XmlDocument不存在,所以我必須使用XDocument。現在我的問題是我正在開發基於SOAP的應用程序,並且我必須解析通過SOAP發送的XML。我在這裏有一些例子,但我不知道如何修改它。 – 2012-04-20 10:48:49

+0

我很高興,你找到了解決方案。爲你添加問題;我無法讀出這個問題。你可以重新解釋一下問題是什麼? – Nasenbaer 2012-04-22 23:30:26

+0

我的問題是我有我的C#SOAP客戶端示例,我需要修改以使用XDocument。我找不到任何地方的一些工作示例如何在WP7上執行SOAP請求。 – 2012-04-23 05:32:07

相關問題