To assist my laziness I tried to write a utility that helps me check the available meeting rooms for booking faster than having to go to Outlook’s Calendar’s Scheduling Assistant.
Luckily, I found that my mail server has enabled Web Services, which should make my job much easier. The WSDL can be found at “https://my.exchange.com/EWS/exchange.asmx”. I tried to use Axis to generate the stubs, but hit an error.
{http://schemas.microsoft.com/exchange/services/2006/types}
ReminderMinutesBeforeStartType>null already exists
I searched and couldn’t find anything. Not wanting to dig into the implementation, I tried to switched to JAXWS. Not going well either.
At least one WSDL with at least one service definition needs to
be provided.
This time I found the answer here. In fact I hit all the same problems as described even after solving this. I’ll repeat the solution here because I realize linking is good, but the sites might get torn down after some time.
Download the Services.wsdl, messages.xsd and types.xsd to your local disk. Edit Services.wsdl to add the service definition manually.
...
With this added I generated the stubs. I used the “-Xnocompile” option to keep the .java files, so I copied them into Eclipse directly. This will be needed as we need to hack the source later.
I tried to call a simple API first – to resolve a name, or “Check Names”. How do I know what to call? Read the documentation.
ExchangeServices factory = new ExchangeServices();
ExchangeServicePortType service = factory.getExchangeServicePort();
// prepare request
ResolveNamesType request = new ResolveNamesType();
request.setUnresolvedEntry("francis");
// prepare response
Holder responseHolder =
new Holder();
service.resolveNames(request, responseHolder);
ResolveNamesResponseMessageType response =
(ResolveNamesResponseMessageType) responseHolder.value.getResponseMessages()
.getCreateItemResponseMessageOrDeleteItemResponseMessageOrGetItemResponseMessage()
.get(0).getValue();
for (ResolutionType resolution: response.getResolutionSet().getResolution()) {
System.out.printf("%s: %s", resolution.getMailbox().getName(),
resolution.getMailbox().getEmailAddress());
}
I hit the isNil problem also as described in the guide, so just comment out the fields that you are not using in ExchangeServicePortType such that you are left with the request and response.
This example is meant to demonstrate how to access Exchange with Java Web Services. If you use it you will likely need to handle errors, exceptions, nulls and the like.
Part II will show how to query the resource availability, and Part III shows how to display this results graphically using JFreeChart.