2012-04-19 3 views
6

в моем приложении для телефона Windows Мне нужно использовать класс 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 Edit - Добавлен 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

+0

Возможно, стоит проверить: [Как использовать веб-сервис в приложении Windows Phone 7] (http://www.codeproject.com/Questions/355937); [Windows Phone 7 в 7: Подключение к веб-службам] (http://msdn.microsoft.com/en-us/gg241261.aspx); [Использование веб-службы ASMX с Windows Phone 7] (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

ответ

0
+1

Хорошо, я получаю это XmlDocument не существует здесь, поэтому я должен использовать XDocument. Теперь моя проблема в том, что я разрабатываю приложение на основе SOAP, и мне приходится разбирать XML-сообщение через SOAP. У меня есть пример, но я не знаю, как его изменить. –

+0

Я рад, что вы нашли решение. Вы добавили вопрос; Я не могу зачитать вопрос. Можете ли вы перефразировать его, пожалуйста, какой вопрос? – Nasenbaer

+0

Моя проблема в том, что у меня есть пример клиента C# SOAP, который мне нужно изменить для работы с XDocument. Я не могу найти какой-либо рабочий пример, как делать SOAP-запросы на WP7. –