exchange web service error - the remote server returned an error 405 method not allowed

user1334890 picture user1334890 · Apr 15, 2012 · Viewed 8.1k times · Source

I'm trying to send a mail via the exchange web service. I looked into the msdn and find some help. Every time I try to run this code i'm getting the above error :( I try read almost everywhere...

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);

service.Credentials = new WebCredentials("My user name", "my pass");

System.Net.ServicePointManager.ServerCertificateValidationCallback =
        ((sender, certificate, chain, sslPolicyErrors) => true);

service.Url = new Uri("my web service url.WSDL");
    EmailMessage appointment = new EmailMessage(service);

appointment.Subject = "Test by me";
appointment.Body = "DateTime.Now";
appointment.ToRecipients.Add("[email protected]");

appointment.SendAnd

SaveCopy();

Answer

Mikael Svenson picture Mikael Svenson · Apr 16, 2012

When setting the url to the service, you should in fact use the asmx, and not the wsdl link.

service.Url = new Uri("https://server/EWS/Exchange.asmx");

That should make it work.