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.
You may have noticed that this post is about two months late. Time flies, doesn’t it? The previous post on an introduction to web services and how they work with ASP.NET provided you with a cursory glance. This post will provide you will how to implement a very basic web service both on the server side for consumption and the client side for use in an application.
Visual Studio 2005 or 2008
Basic knowledge of C#
Basic knowledge of ASP.NET Web Services
Step 1 – Create the ASP.NET Web Service
Visual Studio –> File –> New –> Project… –> Visual C# –> Web –> ASP.NET Web Service Application
Once the web service application project is created, notice that a templated web service was also created (Service1.asmx). The only section of this template to be worried about at the moment is the HelloWorld method marked with the [WebMethod] attribute. Marking methods as a [WebMethod] identifies that they will be used by an external caller through XML SOAP communication and are required to be exposed by the web service WSDL described in the previous post.
Make sure the HelloWorld method looks exactly like below.
That is literally all it takes to expose a web service method to the world! Press F5 to begin debugging this application in a local web server and continue to Step 2.
Step 2 – Utilize the Exposed Web Service Methods
One thing to note is that because web services are implemented via XML, any application that can properly serialize commands into the correct format as described by the web service WSDL has the ability to utilize web services. That said, the following section will be written using a simple C# console application.
Visual Studio –> File –> New –> Project… –> Visual C# –> Windows –> Console Application
Like library references, you need to add a reference to the URL path of the hosted web service. In the case of this article, the web service is hosted locally in the previous step.
In the main project of the solution explorer, right click Web References –> Add New Web Reference…
In the URL textbox, copy and paste the URL found in your browser that popped up from Step 1 when you pressed F5 to debug.
Press the Go button to the right of the URL textbox to search for any exposed methods at the URL provided.
When found, enter a name for the Web reference in the bottom right (I named it localhost.)
Press add reference to allow Visual Studio to create classes that allow consumption of the web service.
Add the following code to the Main method. Make sure you change “localhost” to whatever you called your web reference and change Service1 to the name of your exposed web service class.
NOTE: Microsoft no longer suggests using this method of web services, but it is useful knowledge if you are supporting legacy systems or are still required to implement these features for business purposes. This method of web service is still useful for internal operations that do not require high security.
Below is an overview image of common web service architectures. It’s easiest to think of web services at “web methods” contained within a “web library” that contains methods to be executed on a server. The strength of this approach is that all communication is done in a standard XML format, regardless of the platforms communicating. This allows for brand new systems to communicate with extremely legacy systems, assuming that each system can properly implement a valid SOAP request and response according to the WSDL contract.
Client: Any application that requires consumption of whatever methods the web service is exposing. Web Server: A process that hosts the web services for consumption. Broker: Provides the definition of the web services being exposed. SOAP: XML formatted request and results containing data according to the WSDL (see below.) WSDL: Definition language describing which method to execute, what parameters the method requires, what data types the parameters are, what results will be returned from the web service, and what data type to expect back from the web service.
A common SOAP request with a body but no header. Note that the method being executed is defined in the <m:GetStockPrice> tag and the parameters passed are described in the <m:StockName> tag.
A common SOAP response with a body but no header. Note that the response being returned is defined in the <m:GetStockPriceResponse> tag and the return value is described in the <m:StockNamResponsee> tag.