700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > wsdl和soap协议详细解析

wsdl和soap协议详细解析

时间:2023-05-11 09:50:07

相关推荐

wsdl和soap协议详细解析

1.服务端:

package zhou;import javax.jws.WebService;/** 可写成接口形式去实现* 实现类必须指定接口包路径* @WebService(endpointInterface = "...")* */@WebService(targetNamespace = "http://192.168.0.108:8099/hello")public class PersonService {public String sayHello(String name) {return name + "hello";}}

2.启动服务端调用:

import zhou.PersonService;import javax.xml.ws.Endpoint;public class Publisher {public static void main(String[] args) {Endpoint publish = Endpoint.publish("http://192.168.0.108:8099/hello", new PersonService());}}

浏览器访问:

http://192.168.0.108:8099/hello?wsdl

WSDL:webservice描述语言

读的方式:从下向上

<!--Published by JAX-WS RI (http://jax-). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><!--Generated by JAX-WS RI (http://jax-). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><definitions xmlns:wsu="http://docs.oasis-/wss//01/oasis-01-wss-wssecurity-utility-1.0.xsd"xmlns:wsp="/ns/ws-policy" xmlns:wsp1_2="/ws//09/policy"xmlns:wsam="//05/addressing/metadata"xmlns:soap="/wsdl/soap/" xmlns:tns="http://192.168.0.108:8099/hello"xmlns:xsd="/2001/XMLSchema" xmlns="/wsdl/"targetNamespace="http://192.168.0.108:8099/hello" name="PersonServiceService"><!--types:对输入输出的消息体的约束schema--><types><xsd:schema><xsd:import namespace="http://192.168.0.108:8099/hello"schemaLocation="http://192.168.0.108:8099/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:具体的服务类的元素,在portType内部有多个operation,operation就是服务类中的方法message:输入输出的消息体,分别对应着服务端接收的参数和响应的返回值,消息是以soap为协议,这个协议是http方式的请求,请求体是xml,这个xml不能随便写,需要约束使用schema--><portType name="PersonService"><operation name="sayHello"><input wsam:Action="http://192.168.0.108:8099/hello/PersonService/sayHelloRequest" message="tns:sayHello"/><output wsam:Action="http://192.168.0.108:8099/hello/PersonService/sayHelloResponse"message="tns:sayHelloResponse"/></operation></portType><!--binding:把服务访问点和服务类绑定在一起,不需要关心元素的内部,要关心的是type属性,这个属性指定了绑定了服务类的xml元素(portType)--><binding name="PersonServicePortBinding" type="tns:PersonService"><soap:binding transport="/soap/http" style="document"/><operation name="sayHello"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation></binding><!--服务访问点的集合,可以有多个元素的name属性很重要,调用时需要使用--><service name="PersonServiceService"><!--port:服务访问点,元素的name属性调用时需要使用binding:属性指定了服务访问点和服务类绑定元素--><port name="PersonServicePort" binding="tns:PersonServicePortBinding"><soap:address location="http://192.168.0.108:8099/hello"/></port></service></definitions>

XSD:http://192.168.0.108:8099/hello?xsd=1

<!--Published by JAX-WS RI (http://jax-). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.--><xs:schema xmlns:tns="http://192.168.0.108:8099/hello" xmlns:xs="/2001/XMLSchema" version="1.0"targetNamespace="http://192.168.0.108:8099/hello"><xs:element name="sayHello" type="tns:sayHello"/><xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/><xs:complexType name="sayHello"><xs:sequence><xs:element name="arg0" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType><xs:complexType name="sayHelloResponse"><xs:sequence><xs:element name="return" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType></xs:schema>

消息体:请求与响应 (IDEA需要装SOAP的插件)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。