webService 如何用jquery ajax调用呢

发布于 2022-09-05 10:19:06 字数 3908 浏览 13 评论 0

因为之前完全没做过webService 直接在网上找的demo
java代码:


package demo; 
 
import javax.jws.WebParam; 
import javax.jws.WebService; 
import javax.xml.ws.Endpoint; 
 
@WebService 
public class JdkWebService { 
 
    public String doSomething(@WebParam(name="value", targetNamespace = "http://demo/", mode = WebParam.Mode.IN)String value) { 
        return "Just do it," + value + "!"; 
    } 
     
    public static void main(String[] args) { 
        Endpoint.publish("http://localhost:8099/jdkwsdemo/demo.JdkWebService", new JdkWebService()); 
    } 
 } 

运行之后再网页输入 http://localhost:8099/jdkwsde...
显示如下

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--
 Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. 
-->
<!--
 Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. 
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://demo/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://demo/" name="JdkWebServiceService">
<types>
<xsd:schema>
<xsd:import namespace="http://demo/" schemaLocation="http://localhost:8099/jdkwsdemo/demo.JdkWebService?xsd=1"/>
</xsd:schema>
</types>
<message name="doSomething">
<part name="parameters" element="tns:doSomething"/>
</message>
<message name="doSomethingResponse">
<part name="parameters" element="tns:doSomethingResponse"/>
</message>
<portType name="JdkWebService">
<operation name="doSomething">
<input wsam:Action="http://demo/JdkWebService/doSomethingRequest" message="tns:doSomething"/>
<output wsam:Action="http://demo/JdkWebService/doSomethingResponse" message="tns:doSomethingResponse"/>
</operation>
</portType>
<binding name="JdkWebServicePortBinding" type="tns:JdkWebService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="doSomething">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="JdkWebServiceService">
<port name="JdkWebServicePort" binding="tns:JdkWebServicePortBinding">
<soap:address location="http://localhost:8099/jdkwsdemo/demo.JdkWebService"/>
</port>
</service>
</definitions>

说实话我不是太看得懂这些东西 目前正在网上找关于这个的资料 现在我想用jquery 的 ajax 去调用这个webservise
我估计肯定不是这么写 但是我在网上确实没找到明确的写法 目前了解可能需要用到XML格式 但是具体怎么做我确实不太清除

    $.ajax({
        type: 'POST',
        contentType: 'application/json',
        url: 'http://localhost:8099/jdkwsdemo/demo.JdkWebService/doSomething',
        data: {value:"ss"},
        dataType: 'json',
        success: function (result) {
            alert(result.d);
        }
    });
八月 17, 2017 10:16:53 上午 com.sun.xml.internal.ws.transport.http.server.WSHttpHandler handleExchange
警告: 无法处理 HTTP 方法: OPTIONS

可能是 contentType 这个参数不对 但是我不知道正确应该填什么 求大神给指一条明路T T
对了对了可能还有个跨域的问题 我听人说跨域的问题加个注解就能解决了但是我不知道加什么注解 加在哪里啊

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

久而酒知 2022-09-12 10:19:06

如果用 Ajax 调用,后台可以考虑不用 WSDL,直接返回 JSON。
WSDL 是 XML 描述,所以 dateType 改成 xml 试试,不过要自己解析 WSDL 的 XML 还是麻烦,看能不找个 WSDL 的前端解析库(如果有,估计都带调用接口了)。

彩扇题诗 2022-09-12 10:19:06

这里有一个实现,不是英文的。

夏花。依旧 2022-09-12 10:19:06

saop(webservice)已经有些过时了,如果不是升级现有项目,最好使用REST这种更轻快的架构

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文