Error Integrating EWS 2.2 with Windows Phone 8.1 App

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

March 2nd, 2015 7:10am

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.
Free Windows Admin Tool Kit Click here and download it now
March 2nd, 2015 1:56pm

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

March 2nd, 2015 2:56pm

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.
Free Windows Admin Tool Kit Click here and download it now
March 2nd, 2015 8:09pm

Thanks Jason,

One more help, wondering if you would be able to answer this.

Can I get a list of email accounts configured on my Windows Phone 8.1 through some api/sdk. I am trying to extend some functionality of the default app. So rather creating a page for user to enter Exchange Account details and configure it, if I can get list of email accounts configured on phone, that would be easier from complexity as well as user experience perspective.

Appreciate your quick response and help

Regards,

Nasir Chandwale

March 18th, 2015 2:03pm

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

Free Windows Admin Tool Kit Click here and download it now
April 10th, 2015 3:43pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics