File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Consuming SOAP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Consuming SOAP" Watch "Consuming SOAP" New topic
Author

Consuming SOAP

Fabio Fonseca
Greenhorn

Joined: Jan 19, 2006
Posts: 29
Hello, guys!

I'm having a problem right now that is burning what is lack of my brain. I'm trying call a method in a wsdl file which is located in another server. I don't have access to this server nor I know which tecnology they used to create the wsdl file. What I need to do is to call this method and use its return value (a single string) to create a windows media object.

My first thought was on coding it using AJAX, but I wasn't successful. I skimmed through many tutorials, but not a single one helped me. By reading, a found that - maybe - there is a security issue with using javascript which prevents me to access external wsdl files. Is that correct?

is there any solution to that? Do I have to install/learn/implement this solution using Axis? For the time being, I don't want to feed any webservice information, just to consume it.

Many thanks in advance,

Fabio
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42929
    
  68
I think you have the terminology (and maybe technology) mixed up. A WSDL file describes a Web Service - it is not generally used for accessing it.
It is possible to consume a WS in JavaScript using the XmlHttpRequest object; check the Web Services FAQ for links to a couple of introductory articles that help in doing this.
[ February 08, 2006: Message edited by: Ulf Dittmer ]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Be sure to visit the Web service FAQ to find clarification.

I'm trying call a method in a wsdl file which is located in another server.

You don't call a method in a WSDL file. The WSDL (Web Services Description Langauge) merely describes the Web Service. If the WSDL is complete you will find the URL of the web service in the port element.

I don't have access to this server

It�s going to be "difficult" to call the service if you don�t have "access" to the server.
nor I know which tecnology they used to create the wsdl file.

That shouldn�t matter.
What I need to do is to call this method and use its return value (a single string) to create a windows media object.

My first thought was on coding it using AJAX, but I wasn't successful. I skimmed through many tutorials, but not a single one helped me. By reading, a found that - maybe - there is a security issue with using javascript which prevents me to access external wsdl files. Is that correct?

I presume in AJAX you would HTTP-POST a SOAP message structured to the specifications of the WSDL to the URL specified in the WSDL.
But again, if you don�t have access to the server, AJAX can�t help you.
Do I have to install/learn/implement this solution using Axis?

If you don�t have access to the server/web service you are going to have to create a mock web service to test against. That mock web service has to expose the interface as specified by the WSDL. You can use Tomcat/Axis, ASP.NET or whatever to do that. Your chosen framework will usually have a tool that can generate server stubs from a WSDL � however you will still have to code the service to return the results you want.
For the time being, I don't want to feed any webservice information, just to consume it.

As long as you don�t have access to a service that matches the interface specified by the WSDL you will have create you own stripped down version.
Fabio Fonseca
Greenhorn

Joined: Jan 19, 2006
Posts: 29
Thanks guys for the promptly replies!

I got it working with ajax, but I don't know if it would be useful. Anyway, I will share with others what I discovered. Maybe someone is trying to implemente something like that and is having problems.

First thing, I got this XML tool called Stylus Studio to check if everything was ok with the WSDL file in the other server. From the Stylus Studio I was able to send an envelope to the method I should call, with the arguments required. From there I got an example of the envelope I should send in order to receive the return value of the method.

Ok, then I plugged the envelope code in the XMLHttpRequest using setRequestHeader and send methods.

Example:



Ok, it works alright. But there's still the security problems with the browsers. The user will receive that dreadful security warning every now and then (Good discussion about this subject I found in the book AJAX in Action) . Dunno if my company will accept that.

So.. I'm gonna to play with this little thing I found yesterday:

SOAP taglib ver. 1.5
http://www.servletsuite.com/servlets/soaptag.htm

Let's see what happens.

[ February 09, 2006: Message edited by: Fabio Fonseca ]
[ February 09, 2006: Message edited by: Fabio Fonseca ]
Fabio Fonseca
Greenhorn

Joined: Jan 19, 2006
Posts: 29


For the unknown greenhorn that will someday end up here, the taglib above worked all right. It allowed me to send my SOAP envelope and get the replie right on my jsp. But that wasn't the final solution. I used jsp as a proxy to get the SOAP response and then used AJAX to parse and use it. Just remember to make your jsp content XML using
 
 
subject: Consuming SOAP