locked
HTTPWebResponse throws error "Method not supported" while accessing inbox using SOAP EWS RRS feed

  • Question

  • HI,

    I am trying to access the EWS through SOAP in Windows Phone 8.1 App. As the EWS Managed API is not supported in Phone App, I tried using HTTPWebRequest.

    I tried sample code in a Command Application as it works, but the same code doesn't work in Windows App. Below are both sample codes -

    Command Application code that works

    public bool Request(string URL, string RequestXML, NetworkCredential UserCredentials)

            {

                HttpWebRequest SoapRequest = (HttpWebRequest)WebRequest.Create(URL);

                StreamWriter RequestWriter=null;

                Stream ResponseStream=null;

                HttpWebResponse SoapResponse=null;

                try

                {

                    SoapRequest.AllowAutoRedirect = false;

                    SoapRequest.Credentials = UserCredentials;

                    SoapRequest.Method = "POST";

                    SoapRequest.ContentType = "text/xml";

                   

                    RequestWriter = new StreamWriter(SoapRequest.GetRequestStream());

                    RequestWriter.Write(RequestXML);

                    RequestWriter.Close();

                    SoapResponse = (HttpWebResponse)SoapRequest.GetResponse();

                    if (SoapResponse.StatusCode == HttpStatusCode.OK)

                    {

                        ResponseStream = SoapResponse.GetResponseStream();

                        ResponseEnvelop = XElement.Load(ResponseStream);

                        return true;

                    }

                    else

                    {

                        return false;

                    }

                }

                catch(Exception ex)

                {

                    ResponseEnvelop = null;

                    return false;

                    throw ex;

                }

                finally

                {

                    SoapRequest = null;

                    RequestWriter.Dispose();

                    RequestWriter = null;

                    ResponseStream.Dispose();

                    ResponseStream = null;

                    SoapResponse.Dispose();

                    SoapResponse = null;

                }

            }

    -------------

    Windows Phone App Code

    However some methods are not available in Windows App, so tried below code. There are no compile errors but I receive error "Method not supported". I am trying from weeks but no luck, wondering is some help is available

    public async Task<bool> Request(string URL, string RequestXML, NetworkCredential UserCredentials)

            {

                HttpWebRequest SoapRequest = (HttpWebRequest)WebRequest.Create(URL);

                StreamWriter RequestWriter = null;

                Stream ResponseStream = null;

                WebResponse SoapResponse = null;

                try

                {

                    SoapRequest.Credentials = UserCredentials;

                    SoapRequest.Method = "POST";

                    SoapRequest.ContentType = "text/xml";

                    RequestWriter = new StreamWriter(await System.Threading.Tasks.Task<Stream>.Run(() => SoapRequest.GetRequestStreamAsync()));

                    RequestWriter.AutoFlush = true;

                    RequestWriter.Write(RequestXML);

                    SoapResponse = await System.Threading.Tasks.Task<Stream>.Run(() => SoapRequest.GetResponseAsync());

                    ResponseStream = SoapResponse.GetResponseStream();

                    ResponseEnvelop = XElement.Load(ResponseStream);

                    return true;

                }

    Appreciate some quick help

    Thanks,

    Nasir

    Friday, April 10, 2015 8:00 PM