Exchange Server 2007 and 2010 offer web services that can be accessed via standard SOAP messages. This post will hopefully help you in consuming a very specific web service operation (free/busy data) from your Java environment. I expect that you can take the information found in this post and extend it to other operations. Please note that I will not discuss how to setup Exchange Web Services and will instead assume that such a service is already operational and online.
I cannot guarantee that this is the best, fastest, or most efficient way to get this working. These are the steps that I have compiled through self-teaching, reading various Microsoft documentation, and sifting through a large amount of blogs on separate issues that collectively guided me to the solution. Unlike most of the guides I found, this post should take you from the beginning of the coding process all the way to the end.
The first step is to obtain the WSDL and XSD files that describe the Exchange Web Services. These are usually hosted in the same location as the actual ASMX web service. I only have experience with the setup I use at my company, so results my differ for your Exchange setup.
- Download Services.wsdl to local folder from URL to Exchange Web Service (ie. https://webmail.company.com/ews/Services.wsdl)
- Download messages.xsd to local folder from URL to Exchange Web Service (ie. https://webmail.company.com/ews/messages.xsd)
- Download types.xsd to local folder from URL to Exchange Web Service (ie. https://webmail.company.com/ews/types.xsd)
Microsoft likes to make things complicated and this is true with the files we just downloaded. The WSDL does not contain a ‘services’ tag so the importer we use to create the proxy classes will not work properly.
- Edit the Services.wsdl file and add the following as the last tag in the main tag.
<wsdl:service name="ExchangeWebService"<wsdl:port name="ExchangeWebPort" binding="tns:ExchangeServiceBinding"<soap:address location="https://webmail.company.net/ews/exchange.asmx" /</wsdl:port</wsdl:service
- Download this XSD file to the same directory as the above three: http://www.w3.org/2009/01/xml.xsd
- Edit the types.xsd file that we downloaded by changing the <import namespace> tag to the following:
<xs:import namespace=“http://www.w3.org/XML/1998/namespace” schemaLocation=“xml.xsd”/
- Edit Services.wsdl by adding <services> section to end. See  for tag to add to .wsdl.
- Edit types.xsd to point to correct xml.xsd schema. <xs:import namespace=“http://www.w3.org/XML/1998/namespace” schemaLocation=“xml.xsd”/>
Alright, enough editing, time to create the proxy classes so that we can finally call this service.
- Open a command prompt, change directory to the folder that contains your WSDL and XSD files from above
wsimport -keep -Xnocompile Services.wsdl -wsdllocation http://localhost/wsdl/ExchangeWebService.wsdlto generate proxy classes
wsimport is the name of the Java tool that will parse the WSDL and generate Java class files from the schema. Here is what the flags do:
- keep: keeps the generated files
- Xnocompile: does not create compiled .class files (you’ll see why in a second)
- Services.wsdl: name of the WSDL file to parse
- -wsdllocation http://localhost/wsdl/ExchangeWebService.wsdl: this will generate the proxy classes and tell them to point to this temporary and non-existent location (you’ll see why in a minute)
The generated files are in a long tree of folders.
- Go all the way down to the messages folder
- Edit ExchangeServicePortType.java