Tag: web services

Free/Busy Data from Exchange Web Services via Java

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 [1] 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
  • Type wsimport -keep -Xnocompile Services.wsdl -wsdllocation http://localhost/wsdl/ExchangeWebService.wsdl to 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
Read more

ASP.NET Web Services Part 2

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.
public String HelloWorld()
     return "Hello World";
  • 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.
localhost.Service1 webService1 = new localhost.Service1();
  • Assuming that the web service local server is running properly from Step 1, press F5 to debug the console application.
Read more

ASP.NET Web Services

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.

<?xml version="1.0"?> 
	xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> 
	<soap:Body xmlns:m="http://www.example.org/stock">

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.

<?xml version="1.0"?> 
	xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> 
	<soap:Body xmlns:m="http://www.example.org/stock">

Stay tuned for the next post which will include how to create a web service client and server in Visual Studio 2008 using C#.… Read more