java post调用ws,如何调用Java web服务(JAX-WS)从阿贾克斯?

博主遇到了在JavaScript中通过AJAX访问JAX-WS Web服务的困难。问题在于使用默认URL无法成功调用服务。解决方案是使用POST方法打开URL,并设置SOAPAction请求头和正确的SOAP Envelope。通过这样做,博主能够成功访问Java Web服务。
摘要由CSDN通过智能技术生成

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

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值