因为之前完全没做过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
对了对了可能还有个跨域的问题 我听人说跨域的问题加个注解就能解决了但是我不知道加什么注解 加在哪里啊
如果用 Ajax 调用,后台可以考虑不用 WSDL,直接返回 JSON。
WSDL 是 XML 描述,所以
dateType
改成xml
试试,不过要自己解析 WSDL 的 XML 还是麻烦,看能不找个 WSDL 的前端解析库(如果有,估计都带调用接口了)。