2012-04-19 14 views
6

私のWindowsの電話アプリXmlDocumentクラスを使用する必要があります。しかし、私はまだ私が参照して using System.XmlWindows Phone - XmlDocumentが見つかりません

を追加しましたエラー

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

を取得しかし、それは助けをdoesntの。

これは私がXDocument 編集で動作するように変更する必要があることを、私のSOAPのコード例である - を追加しました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 to Xml/XDocumentを使用していませんか? – BrokenGlass

+0

おそらくチェック価値があります:[Windows Phone 7アプリケーションでWebサービスを使用する方法](http://www.codeproject.com/Questions/355937); [Windows Phone 7 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

答えて

0
+1

XmlDocumentはここには存在しないので、XDocumentを使用する必要があります。今私の問題は、私はSOAPベースのアプリケーションを開発していると私はSOAPを送信するXMLを解析する必要があります。ここにいくつかの例がありますが、それを変更する方法はわかりません。 –

+0

私は満足しています。解決策を見つけました。あなたは質問を追加しました。私はその質問を読むことができません。あなたはそれが何であるかを言い換えることができますか? – Nasenbaer

+0

私の問題は、C#SOAPクライアントの例があることです。これは、XDocumentで動作するように変更する必要があります。 WP7でSOAPリクエストを実行する方法については、実際のところどこでも見つけることができません。 –

関連する問題