none
Error Integrating EWS 2.2 with Windows Phone 8.1 App RRS feed

  • Question

  • Hi,

    I am new to Windows Phone development. I have a basic need to access the Exchange Calendar.

    I am using Windows Phone 8.1 SDK and Exchange Web Service 2.2 SDK.

    As a first step I tried to use the Microsoft.Exchange.WebServices.Autodiscover dll to find the end points of the Exchange Server.

    However on the first code statement

    Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService service = new AutodiscoverService();

    It throws an exception –

    An exception of type 'System.IO.FileNotFoundException' occurred in Microsoft.Exchange.WebServices.DLL but was not handled in user code

    'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll

    I further tried some debugging and using Code Analyser I get following warnings –

    Microsoft.Exchange.WebServices.dll: warning CS1684: Reference to type 'System.Net.IPAddress' claims it is defined in 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhoneApp\v8.1\System.dll', but it could not be found.

    And

    C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.Auth.dll: warning MSB3817: The assembly "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.Auth.dll" does not have a NeutralResourcesLanguageAttribute on it. To be used in an app package, portable libraries must define a NeutralResourcesLanguageAttribute on their main assembly (ie, the one containing code, not a satellite assembly).

    I am not sure what the issue is, but when I try the same code it works in a Command Application. There are other errors but not the above ones. It at least executes few statements.

    Can someone please help resolve this error and point me to links where I can find sample code with Windows Phone 8.1 implementation?

    Thanks in Advance

    Nasir

    Monday, March 2, 2015 7:10 AM

All replies

  • The EWS Managed API isn't compatible with Windows Phone. You can invoke Exchange Web Services from the phone, but you have to create and send SOAP requests yourself, you can't use the managed API.
    Monday, March 2, 2015 1:56 PM
    Moderator
  • Thank you Jason for the clarification.

    Can you point me to some URL where I can understand and learn more about "Calling Exchange Server and Implementing Functionality using SOAP/REST Based API" using Windows Phone 8.1

    Appreciate your help as I am new to Windows Phone development

    Thanks,

    Nasir

    Monday, March 2, 2015 2:56 PM
  • The Web Services documentation is pretty good about showing you how to do a particular task with the managed API or with SOAP. Topics will usually have a section like "Doing X with the EWS Managed API", and a corresponding "Doing X with EWS". The EWS section shows you the format of the SOAP call. If you're asking about sending SOAP calls from Windows Phone, I believe you can use HttpWebRequest on the phone.
    Monday, March 2, 2015 8:09 PM
    Moderator
  • The Web Services documentation is pretty good about showing you how to do a particular task with the managed API or with SOAP. Topics will usually have a section like "Doing X with the EWS Managed API", and a corresponding "Doing X with EWS". The EWS section shows you the format of the SOAP call. If you're asking about sending SOAP calls from Windows Phone, I believe you can use HttpWebRequest on the phone.

    Hi Jason,

    I tried using HTTPWebRequest, in a sample command line project and it works fine. Below is the code -

    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;

                }

            }

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

    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 7:42 PM