HTTP SOAP
POST/saveUser.do HTTP/1.1 POST/saveUser.do HTTP/1.1
Content-Type:text/html;charset=utf8 Content-Type:text/xml;charset=utf8
Host:192.168.1.1 Host:192.168.1.1
...[空行] ...[空行]
name=jack&age=100&address=beijing <Envelope>
<body>
.......
</body>
<Envelope>
package com.cgm.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class WS_01 {
public String sayHello(String name){
return "hello"+name;
}
@WebMethod(exclude=true)
public String sayHello1(String name){
return "hello"+name;
}
public static void main(String[] args) {
Endpoint.publish("http://192.168.111.100:6789/hello", new WS_01());
}
}
webservice生成客户端源码 cmd 切换到要生成的文件目录下 wsimport -s . http://192.168.111.100:6789/hello?wsdl 回车
<?xml version="1.0" encoding="UTF-8" ?>
- <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01.
-->
- <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01.
-->
- <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://ws.cgm.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.cgm.com/" name="WS_01Service">
- <types>
- <xsd:schema>
<xsd:import namespace="http://ws.cgm.com/" schemaLocation="http://192.168.111.100:6789/hello?xsd=1" />
</xsd:schema>
</types>
- <message name="sayHello">
<part name="parameters" element="tns:sayHello" />
</message>
- <message name="sayHelloResponse">
<part name="parameters" element="tns:sayHelloResponse" />
</message>
- <portType name="WS_01">
- <operation name="sayHello">
<input wsam:Action="http://ws.cgm.com/WS_01/sayHelloRequest" message="tns:sayHello" />
<output wsam:Action="http://ws.cgm.com/WS_01/sayHelloResponse" message="tns:sayHelloResponse" />
</operation>
</portType>
+ <binding name="WS_01PortBinding" type="tns:WS_01">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <operation name="sayHello">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
</binding>
- <service name="WS_01Service">
- <port name="WS_01Port" binding="tns:WS_01PortBinding">
<soap:address location="http://192.168.111.100:6789/hello" />
</port>
</service>
</definitions>
客户端调用
package com.cgm.ws;
public class App {
public static void main(String[] args) {
WS01Service ws01Service=new WS01Service();
WS01 w=ws01Service.getWS01Port();
String a=w.sayHello("nanann");
System.out.println("============"+a);
}
}
POST/saveUser.do HTTP/1.1 POST/saveUser.do HTTP/1.1
Content-Type:text/html;charset=utf8 Content-Type:text/xml;charset=utf8
Host:192.168.1.1 Host:192.168.1.1
...[空行] ...[空行]
name=jack&age=100&address=beijing <Envelope>
<body>
.......
</body>
<Envelope>
package com.cgm.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class WS_01 {
public String sayHello(String name){
return "hello"+name;
}
@WebMethod(exclude=true)
public String sayHello1(String name){
return "hello"+name;
}
public static void main(String[] args) {
Endpoint.publish("http://192.168.111.100:6789/hello", new WS_01());
}
}
webservice生成客户端源码 cmd 切换到要生成的文件目录下 wsimport -s . http://192.168.111.100:6789/hello?wsdl 回车
<?xml version="1.0" encoding="UTF-8" ?>
- <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01.
-->
- <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01.
-->
- <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://ws.cgm.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.cgm.com/" name="WS_01Service">
- <types>
- <xsd:schema>
<xsd:import namespace="http://ws.cgm.com/" schemaLocation="http://192.168.111.100:6789/hello?xsd=1" />
</xsd:schema>
</types>
- <message name="sayHello">
<part name="parameters" element="tns:sayHello" />
</message>
- <message name="sayHelloResponse">
<part name="parameters" element="tns:sayHelloResponse" />
</message>
- <portType name="WS_01">
- <operation name="sayHello">
<input wsam:Action="http://ws.cgm.com/WS_01/sayHelloRequest" message="tns:sayHello" />
<output wsam:Action="http://ws.cgm.com/WS_01/sayHelloResponse" message="tns:sayHelloResponse" />
</operation>
</portType>
+ <binding name="WS_01PortBinding" type="tns:WS_01">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <operation name="sayHello">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
</binding>
- <service name="WS_01Service">
- <port name="WS_01Port" binding="tns:WS_01PortBinding">
<soap:address location="http://192.168.111.100:6789/hello" />
</port>
</service>
</definitions>
客户端调用
package com.cgm.ws;
public class App {
public static void main(String[] args) {
WS01Service ws01Service=new WS01Service();
WS01 w=ws01Service.getWS01Port();
String a=w.sayHello("nanann");
System.out.println("============"+a);
}
}