views:

895

answers:

2

Hi

I am developing java web services (JAX-WS) to insert data into mysql DB and retrieve it. This web service has two methods i.e. fetchFromDB and insertIntoDB. Services seems to be running fine when I test them using netbeans IDE.

Address: /CalculatorWSService
WSDL:    /CalculatorWSService?wsdl

but when I try to access it using AJAX's xmlHttpRequest object by providing url http://localhost:8080/CalculatorApp/CalculatorWSService. It is not able to access it. I have developed C# web services and It has been so easy to access them with a url but java web services don't seem to follow that.

My question is

What url to use to access the web service operations in AJAX? (Do I need to use '?wsdl' in the url? Is there a javascript ajax library to easily access JAX-WS web services? Apache Axis web services are a better choice over JAX-WS? Please help me, Thanks, Jay

A: 

From the client's perspective, I wasn't expecting significant differences between Axis and JAX-WS. Everything the client needs should be in the WSDL.

One thing that sometimes happens is that the URL used when developing a WebService references the develpoment host and port (and maybe even the ContextRoot) When deployed to a particular server any of those could be changed. Ideally a new WSDL could be created with new "binding" information.

My first step would be to point a browser directly at the Web Service you want to invoke. In my environments that returns a nice "Hi this is a Web Service" kind of message. If you get 401 not found errors then you just need to study exactly how the web service was deployed. Was a different port or context root specified?

djna
+1  A: 

Hi!!, I was having the same problem of yours, couldn't invoke a Jax-ws web service from Javascript, but i've found a way to do this.

The Url to use can be your same (EndPointAddress) "http://localhost:8080/CalculatorApp/CalculatorWSService"

but when you create the XMLHttpRequest object from javascript you have to:

* Use the POST method to open the URL , i tried with GET but it didn't work for me.
* Set the SOAPAction Request Header to the one in your wsdl, even if its empty "".
* Be very careful with the request body to send, the soap Envelope must be correct.

hope this can help you!.

Bye.
Paul Manjarres.

Paul Manjarres