Exchange Web Service throwing exception
You will recieve the following exception while calling Discover method of ExchangeServiceBinding
System.InvalidOperationException: Discovery document at the URL https://SERVER/EWS/services.wsdl could not be found. ---> System.ArgumentException: The document format is not recognized.
--- End of inner exception stack trace ---
at System.Web.Services.Discovery.DiscoveryDocumentReference.Resolve(String contentType, Stream stream)
at System.Web.Services.Discovery.DiscoveryReference.Resolve()
at System.Web.Services.Discovery.DiscoveryDocumentReference.get_Document()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Discover()
at EWS_Test_Anything.Tasks.TestConnection()
If I do not call Discover method rest of code is working fine, i could access Exchange without any problem.
So what happens when we call Discover method?
Following is the finding from my colleague Matt
Looking at MSDN, https://msdn2.microsoft.com/en-us/library/system.web.services.protocols.soaphttpclientprotocol.discover.aspx, the Discover method is actually part of the base class, SoapHttpClientProtocol, and seems to be looking for the *.disco URL not the *.wsdl URL.
If you look at the MSDN information on Web Service Discovery, https://msdn2.microsoft.com/en-us/library/fxx6cfx2.aspx, you will see the following quote indicating that a DISCO file is not required by a web service…
“…However, a Web site that implements an XML Web service need not support discovery. Another site could be responsible for describing the service, such as an XML Web services directory. Alternatively, there might not be a public means of finding the service, such as when you create the service for private use…”
Looking at the Exchange 2007 virtual directories it doesn’t appear that Microsoft have supplied at DISCO file and being that we have so few entry points we don’t really need one.
Resolution.... Do not call Discover method... there is no need doing it.