Sunday, November 22, 2009

Creating Exchange Service Stub using AXIS 2

I had a good learning experience migrating our calendering functionality from exchange server 2003 to exchange server 2007. And in this post, I have jotted out how to create a proper exchange service client stub using Axis 2.

Creation of client stub is not straight forward as it seems. It is because the stub generated by Axis 2 without any changes to auto generated stub code has one malformed element and as a result the SOAP request is not formed correctly.

The final list of steps I followed are below,

Step-1:
Download axis2- 1.5 from the net and unzip it.

Step-2: Download the Services.wsdl, types.xsd and messages.xsd from https://ExchangeServerURL/ews/Services.wsdl and place the same under the folder axis2- 1.5.

Step-3: In Services.wsdl file we need to add an XML element that defined the service. So add the following piece of code in the end just before the closure of wsdl:definition.

<wsdl:service name="ExchangeService">
    <wsdl:port name="ExchangeServicePort" binding="tns:ExchangeServiceBinding">
        <soap:address location="https://ExchangeServerURL/ews"/>
    </wsdl:port>
</wsdl:service>


Step-4: Execute the below from command prompt to generate the source files. The source files will get generated under axis2-1.5/ews directory.

C:\exchange\axis2-1.5>bin\wsdl2java -d xmlbeans -s -ss -g -o ews -uri Services.wsdl

Step-5: We need to manually change the class ChangeDescriptionTypeImpl in the package com.microsoft.schemas.exchange.services._2006.types.impl so that the XML is formed correctly for the UpdateItem request. The issue was with specifying the element that denotes the property that needs to be changed. The XML was generated with tag but the exchange server was expecting the element . So we need to change the variable PATH$0 in the class from

private static final javax.xml.namespace.QName PATH$0 = new javax.xml.namespace.QName("http://schemas.microsoft.com/exchange/services/2006/types", "Path");

    to

private static final javax.xml.namespace.QName PATH$0 = new javax.xml.namespace.QName("http://schemas.microsoft.com/exchange/services/2006/types", "FieldURI");

Step-6a: The above command also creates ant file that can be used to create the jar file (if ant is installed in windows).

    or

Step-6b: If ant is not available in windows, you can still create the jar file by manually setting the unix paths in the build.xml and running ant from unix.

Step-7: After running ant, the aar and jar file gets created in axis2-1.5\ews\build\lib directory and this can be added to class path and used in programming.

I the next post we will see how to send a mail using the stub we generated.

If you face any issues with the creation or using the stub, provide your questions here and I would be happy to help.

2 comments:

  1. Hi.
    I'm having problems with importing packages (aar and jar) in my project (with ide oracle jdeveloper).
    Could you give me a your email address to contact you?
    Thanks in advance...

    ReplyDelete
    Replies
    1. can you mail it to quality_worker_88 [at] yahoo.com

      Delete