File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Calling a webservice manually Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Calling a webservice manually" Watch "Calling a webservice manually" New topic

Calling a webservice manually

Cobain Smith

Joined: Dec 20, 2010
Posts: 9
While I was figuring out what goes wrong with the generated Axis2 client code (as described here) I grabbed the packet containing the soap message and tried to use that in a ajax call

but I got a HTTP 500 error back.

500 The endpoint reference (EPR) for the Operation not found is /axis2/services/SimpleService?%3C?xml%20version=%221.0%22%20encoding=%22UTF-8%22?%3E%3Csoapenv:Envelope%20xmlns:soapenv=%22 and the WSA Action = null

Then I took the soap message the Web Service Explorer used (or seemed to use) but it also didn't work with that.
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope><soapenv:Body><q0:concatRequest><s1>12</s1><s2>2312341234</s2></q0:concatRequest></soapenv:Body></soapenv:Envelope>

So how should the soap look like?

Here is my wsdl
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577

Hi Cobain,
You have provided detailed information to spot the problem!

You are missing the following two namespace declarations within soapenv:Envelope element of your SOAP message.

(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Cobain Smith

Joined: Dec 20, 2010
Posts: 9
Naren Chivukula wrote:You have provided detailed information to spot the problem!
But I missed to cross-link this thread in the previous. Thanks so far. I'll work on it tomorrow as I have to figure out, what's going on in the generated code. And because I'm still quite new to web services I'm very interested in how everything fits together and what's under the hood ;-)
Cobain Smith

Joined: Dec 20, 2010
Posts: 9
Ok, after hours of wondering why my packet sniffing tool didn't catch up the tcp stream from eclipse I figured out what exactly the Web Service Explorer in eclipse sends to the server.

Changing some parameters in my ajax call changed the http code from the previous 500 to 501 which was good somehow. With that information I know that some headers must be missing. The monitored tcp stream looked like:

POST /axis2/services/SimpleService/ HTTP/1.1
Content-Type: text/xml; charset=utf-8
Content-Length: 325
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: IBM Web Services Explorer
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Connection: close

<soapenv:Envelope xmlns:soapenv="" xmlns:q0="" xmlns:xsd="" xmlns:xsi="">
HTTP/1.1 200 OK
Date: Wed, 12 Jan 2011 15:06:51 GMT
Server: Simple-Server/1.1
Transfer-Encoding: chunked
Content-Type: text/xml; charset=utf-8
Connection: close

<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv=""><soapenv:Body><ns1:concatResponse xmlns:ns1="">asdf1234</ns1:concatResponse>

Aha, the SOAPAction was missing and the contentType wasn't set to application/soap+xml (but application/xml should also work as soap is xml). I don't know what d1 and the latter 0 means, maybe there's something wrong with the encoding (in my packet sniffer). The corresponding symbols with these hex codes don't make any sense. But as the server is responding back correctly those symbols seem to have no impact.

I'll post the ajax call very soon for those who are interested in that.
It is sorta covered in the JavaRanch Style Guide.
subject: Calling a webservice manually
jQuery in Action, 3rd edition