trong ứng dụng điện thoại cửa sổ của tôi Tôi cần sử dụng lớp XmlDocument. Nhưng tôi vẫn nhận được lỗiWindows Phone - Không thể tìm thấy XmlDocument
Error 1 The type or namespace name 'XmlDocument' could not be found (are you missing a using directive or an assembly reference?)
tôi đã thêm tài liệu tham khảo và using System.Xml
nhưng nó không giúp đỡ.
Đây là SOAP dụ mã của tôi, mà tôi cần phải sửa đổi để làm việc với XDocument Edit - Thêm SOAP mã ví dụ
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);
}
}`
tại sao bạn không sử dụng LINQ to Xml/XDocument? – BrokenGlass
Có thể đáng để kiểm tra: [Cách sử dụng webservice trong ứng dụng Windows Phone 7] (http://www.codeproject.com/Questions/355937); [Windows Phone 7 trong 7: Kết nối với dịch vụ web] (http://msdn.microsoft.com/en-us/gg241261.aspx); [Sử dụng dịch vụ web ASMX từ Windows Phone 7] (http://social.msdn.microsoft.com/Forums/wpapps/en-US/38815099-8394-448c-80bf-a93279fbbdac/); [Tạo tham chiếu dịch vụ: Không thể tạo mã cho tham chiếu dịch vụ] (http://software-development-toolbox.blogspot.ru/2009/02/creating-service-reference-failed-to.html) – GSerg