6

in my windows phone app I need to use XmlDocument class. But I still get errors

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

I added reference and using System.Xml

But it doesnt help.

This is my SOAP example code, that I need to modify to work with XDocument Edit - Added SOAP example code

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

1 Answer 1

0

Its supported in WP7

enter image description here

example with Linq is here: http://www.windowsphonegeek.com/tips/wp7-working-with-xml-reading-filtering-and-databinding

source code example: http://www.c-sharpcorner.com/UploadFile/74f20d/read-local-xml-file-from-windows-phone-7/

3
  • 1
    Ok, I get it XmlDocument doesnt exist here so I have to use XDocument. Now my problem is that I am developing SOAP based app and I have to parse XML send throught SOAP. I have here some example but I dont know how to modify it. Apr 20, 2012 at 10:48
  • I am happy, that you found a solution. For you added question; I cannot read out the question. Can you rephrase it please what the question is?
    – Nasenbaer
    Apr 22, 2012 at 23:30
  • My problem is that I have i C# SOAP client example, that I need to modify to work with XDocument. I can not find anywhere some working example how to do SOAP requests on WP7. Apr 23, 2012 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.