如何调用Java web服务(JAX-WS)从阿贾克斯? [英] How to call Java web service (JAX-WS) from AJAX?

查看:511
本文介绍了如何调用Java web服务(JAX-WS)从阿贾克斯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发Java Web服务(JAX-WS),将数据插入到MySQL数据库和检索。这个Web服务有两个方法,即fetchFromDB和insertIntoDB。服务似乎运行良好使用NetBeans IDE当我测试它们。

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

但是当我尝试使用AJAX的xmlHtt prequest目的是通过提供URL 的http://本地主机: 8080 / CalculatorApp / CalculatorWSService 。它不能访问它。我已经开发了C#的Web服务,它有没有这么容易访问它们同一个网址,但Java Web服务似乎并没有遵循这一点。

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.

我的问题是

要使用什么URL来访问Web服务业务AJAX? (我需要使用'?WSDL的网址是什么? 是否有一个JavaScript Ajax库轻松地访问JAX-WS Web服务? Apache Axis的网络服务是在JAX-WS一个更好的选择? 请帮帮我,谢谢,周杰伦

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

推荐答案

我有你的同样的问题,不能从Javascript调用JAX-WS Web服务,但我已经找到了一种方法来做到这一点。

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.

URL中使用可你一样(的EndpointAddress)的http://本地主机:8080 / CalculatorApp / CalculatorWSService

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

但是,当你创建的JavaScript,你必须在XMLHtt prequest对象:

*使用POST方法打开URL,我试着用GET,但它并没有为我工作。
*即使其空设置的SOAPAction请求头与一个在您的WSDL。
*必须非常小心请求主体发送,SOAP信封必须是正确的。照片

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.

希望这能帮助你!

再见。
保罗Manjarres。

Bye.
Paul Manjarres.

这篇关于如何调用Java web服务(JAX-WS)从阿贾克斯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆