2012-04-19 34 views
6

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); 
     } 
    }` 
+2

tại sao bạn không sử dụng LINQ to Xml/XDocument? – BrokenGlass

+0

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

Trả lời

0
+1

Ok, tôi nhận được nó XmlDocument không tồn tại ở đây vì vậy tôi phải sử dụng XDocument. Bây giờ vấn đề của tôi là tôi đang phát triển ứng dụng dựa trên SOAP và tôi phải phân tích cú pháp XML gửi qua SOAP. Tôi có ở đây một số ví dụ nhưng tôi không biết làm thế nào để sửa đổi nó. –

+0

Tôi hạnh phúc, rằng bạn đã tìm thấy một giải pháp. Đối với bạn thêm câu hỏi; Tôi không thể đọc được câu hỏi. Bạn có thể nói lại câu hỏi đó được không? – Nasenbaer

+0

Vấn đề của tôi là tôi có ví dụ máy khách C# SOAP, mà tôi cần sửa đổi để làm việc với XDocument. Tôi không thể tìm thấy bất cứ nơi nào một số ví dụ làm việc làm thế nào để làm SOAP yêu cầu trên WP7. –

Các vấn đề liên quan