WebService入门
WebService入门@(WebService)[WebService,wsdl,soap,uddi]
WebService概述
PS:个人理解, WebService基本概念——SOAP
SOAP的基本格式
PS:其实也就是在一个 HTML协议部分
SOAP协议的组成
请求示例POST /WebServices/WeatherWS.asmx HTTP/1.1
Host: ws.webxml.com.cn
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://WebXml.com.cn/getRegionProvince"
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getRegionProvince xmlns="http://WebXml.com.cn/" /> </soap:Body> </soap:Envelope>
响应示例HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getRegionProvinceResponse xmlns="http://WebXml.com.cn/"> <getRegionProvinceResult> <string>string</string> <string>string</string> </getRegionProvinceResult> </getRegionProvinceResponse> </soap:Body> </soap:Envelope>
WebService基本概念——WSDL
WSDL 1.1标准中元素
WSDL 1.1标准和2.0标准的比较WSDL 1.1标准元素案例WebService基本概念——UDDI
PS:个人理解,UUID主要是用于互联网Web Service的搜索和定位。 使用JDK1.7实现一个简单的WebService基本概念在JDK1.6中JAX-WS规范定义了如何发布一个webService服务。 用Jdk1.6.0_21以后的版本发布一个WebService服务. 其他注意事项: 服务端代码package com.pc.webservice.server;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
/** * WebService Demo * * @author Switch * @data 2016年12月21日 * @version V1.0 */
@WebService
public class HelloWebService {
// 只有非static和非final的方式才能发布为WebService
public String helloWebService(String name) {
return "hello " + name;
}
public static void main(String[] args) {
String address = "http://localhost:6166/hello";
Object implementor = new HelloWebService();
// 通过Endpoint发布WebService服务
// 参数1:发布地址
// 参数2:端点实现对象
Endpoint.publish(address,implementor);
}
}
启动main方法,会发布服务到指定地址上,并监听该地址。 使用wsimport命令生成客户端代码命令为:
常用参数为: 客户端测试代码package com.pc.webservice.test;
import org.junit.Test;
import com.pc.webservice.client.HelloWebService;
import com.pc.webservice.client.HelloWebServiceService;
/** * WebService 测试类 * * @author Switch * @data 2016年12月21日 * @version V1.0 */
public class HelloWebServiceTest {
@Test
public void testHelloWebService() {
// 对应于wsdl中的service
HelloWebServiceService helloWebServiceService = new HelloWebServiceService();
// 对应于wsdl中的port,创建代理对象
HelloWebService proxy = helloWebServiceService.getHelloWebServicePort();
// 使用代理对象,调用HelloWebService提供的服务
// 输出:hello WebService
System.out.println(proxy.helloWebService("WebService"));
}
}
PS:将 GitHub:WebServiceDemo (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |