Tuesday, 9 February 2010

EWS Managed API through a Proxy Server

So I have been doing a bit more EWS stuff recently and part of that was to access an exchange server on the internet from behind a web proxy server. This threw up an error which had me a bit annoyed and after a fair bit of searching the web for an answer I found the following

The upshot being:-
  • You cannot specify a proxy server/credentials on a service by service basis - BAD TIMES
  • You CAN tell your application to use the default credentials for any proxy server it encounters while trying to make a request.. The answer lies in the following bit of code

WebRequest.DefaultWebProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

For VB.NET, just remove the semicolon at the end of the line and place it above where you initialise your Exchange connector. Worked a treat for me ;-)

All credit to Mr David Claux for finding this one....