Archive for August, 2011

wsdl webservice from Outlook Web App

I’m trying to figure out what the Webservice for an Outlook Web App (OWA) can provide me with.

So far, this doesn’t work but I hope I’ll manage to get it to work during this post.

I had the URL for webservice. It look something like this:

https://exchange.myuniversity.edu/EWS/Services.wsdl

Then I wanted to create the client-class-stubs via wsimport . I tried running wsimport from the command line.

First problem: I have to use a proxy. As wsimport works from the console I tried setting the proxy there. As I use Windows 7 proxycfg wasn’t the correct command any more but I had to use

netsh winhttp set proxy proxy.mycompany.com:3128

In case you have put explicity proxy information into the system settings of IE netsh winhttp import proxy source=ie might help. But I only have an automatic configuration there and that didn’t carry over to the command line proxy configuration.

Then I figured that wsimport had it’s own proxy argument and I could get the result via:

wsimport -httpproxy:proxy.mycompany.com:3128 https://exchange.myuniversity.edu/EWS/Services.wsdl

This got me the following error message:

[ERROR] Server returned HTTP response code: 401 for URL: https://exchange.myuniversity.edu/EWS/Services.wsdl,  "https://exchange.myuniversity.edu/EWS/Services.wsdl" needs authorization, please provide authorization file with read access at C:\Users\winusername\.metro\auth or use -Xauthfile to give the authorization file and on each  line provide authorization information using this format : http[s]://user:password@host:port//<url-path>

So I created a file myuni.txt with the line:

https://uniaccountname:unipassword@exchange.myuniversity.edu/EWS/Services.wsdl

(At first I mistakenly thought that I was supposed to download the SSL certificate, but that wasn’t the case.)

I than ran:

wsimport -httpproxy:proxy.mycompany.de:3128 -Xauthfile myuni.txt https://exchange.myuniversity.edu/EWS/Services.wsdl

However I ran into:

parsing WSDL...
[ERROR] Server redirected too many  times (20),  "https://exchange.myuniversity.edu/EWS/Services.wsdl" needs authorization, please provide authorization file with read access at C:\Users\winusername\.metro\auth or use -Xauthfile to give the authorization file and on each line provide authorization information using this format: http[s]://user:password@host:port//<url-path>

I didn’t know how to solve this, so followed Ravi C Kota’s suggestion on Code Ranch to just download the wsdl-file.

However I than got:

 At least one WSDL with at least one service definition needs to be provided.
        Failed to parse the WSDL.

Maybe I have the same problem as Henning Mahlzahn over at social.technet.microsoft.com.

Unfortunately Henning Mahlzahn only links to the URL

http://tp.its.yale.edu/confluence/display/EXCH/Introduction+to+MS+Exchange+Web+Services+via+Java%28JAXWS%29

saying it describes how to change the wsdl file. As this URL is down, I tried to figure out how to correct my wsdl by looking at the amazon.wsdl file at:

http://soap.amazon.com/schemas2/AmazonWebServices.wsdl

Infering from that file I added a service definition in my wsdl file before the last line and after the last </wsdl:binding>. Including the two surrunding lines I had:

    </wsdl:binding>
    <wsdl:service name="ExchangeService">
        <wsdl:port name="ExchangeServicePortType" binding="tns:ExchangeServiceBinding">
            <soap:address location="http://schemas.xmlsoap.org/wsdl/soap/"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

Where I made up the name “ExchangeService”, an I got the names for port and binding from the lines:

   <wsdl:portType name="ExchangeServicePortType">

and

   <wsdl:binding name="ExchangeServiceBinding" type="tns:ExchangeServicePortType">

(On my first try I forgot the “wsdl:”-namespace in front of the port so I got the following error:

parsing WSDL…

Exception in thread “main” com.sun.tools.internal.ws.util.WSDLParseException: Encountered error in wsdl. Check namespace of element <port>

Now the parsing worked a little further and I got to the point where I need the file

parsing WSDL...
[ERROR] C:\cwd\messages.xsd (Das System kann die angegebene Datei nicht finden)

[WARNING] schema_reference.4: Failed to read schema document 'messages.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.  line 5 of file:/C:/crw/modified.Services.wsdl.xml#types?schema1

So I had to download all the files Henning Malzahn listed in his posting: : Services.wsdl, messages.xsd and types.xsd

Those files are located in the same directory on your exchange server as the wsdl. In my case:

https://exchange.myuniversity.edu/EWS/messages.xsd

Running wsimport now got me the new errors:

parsing WSDL...
[WARNING] src-resolve: Cannot resolve the name 'xml:lang' to a(n) 'attribute declaration' component.
  line 3921 of file:/C:/cwd/types.xsd
[WARNING] s4s-elt-invalid-content.1: The content of 'ReplyBody' is invalid.  Element 'attribute' is invalid, misplaced, or occurs too often.
  line 3921 of file:/C:/cwd/types.xsd
[ERROR] undefined attribute 'xml:lang'  line 3921 of file:/C:/cwd/types.xsd

Those errors all reference some line in types.xsd. As the line had a “use=\”optional\”” attribute, I thought I could just comment it out. So I had the following:

<xs:complexType name=”ReplyBody”>
<xs:sequence>
<xs:element minOccurs=”0″ maxOccurs=”1″ name=”Message” type=”xs:string”/>
</xs:sequence>
<!–    <xs:attribute ref=”xml:lang” use=”optional”/>–>
</xs:complexType>

All these changes resulted in compiling code:

parsing WSDL…

generating code…

compiling code…

Note: C:\cwd\.\com\
microsoft\schemas\exchange\services\_2006\messages\ObjectFactory.java uses unche
cked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Now I had to check whether I could use the Web Service features from within Java and I wasn’t too sure about it because I had come across a posting by cheeso on Connecting to Exchange using JAX-WS, part 1 – All About Interop – Site Home – MSDN Blogs where he lists these things he had to do before he was able to use the Web Service:

Let me summarize what I did to get Java to talk to Exchange:

  • Modified the exchange.wsdl to include a service definition, and to remove all occurrences of impersonation, S2SAuth, and MailboxCulture from each wsdl:message.
  • Modified the types.xsd to eliminate the ref=”t:Path”, and replace it with actual elements
  • Use Fiddler2 to trace and debug the SOAP messages.

I forgot to add the -keep option to my wsimport statement. I added it in order to get coding help from eclipse.

At this point I stopped trying for now. What I did was trying to use the amazon web service but it then I read that amazon’s webservice based on soap is not compatible with JAX-WS and that one should use JAX-RPC. Now I wonder whether exchange is compatible.

August 1, 2011 at 3:42 pm Leave a comment


Blog Stats

  • 16,203 hits