• webService 三要素


    WebService(jax-ws)三要素
    
      SOAP: 基于HTTP协议,采用XML格式,用来传递信息的格式。
    
      WSDL: 用来描述如何访问具体的服务。(相当于说明书)
    
      UDDI: 用户自己可以按UDDI标准搭建UDDI服务器,用来管理,分发,查询WebService 。其他用户可以自己注册发布WebService调用。(现在基本废弃)
    
     
    
    1.SOAP(通讯协议)
    
         Simple Object Accrss Protocol,简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一个基于XML的协议,它包括四个部分:
    
    (1)SOAP封装(envelop),封装定义了一个描述消息中的内容是什么,是谁发送的,谁应当接受并处理它,以及如何处理它们的框架;
    
    (2)SOAP编码规则,用于表示应用程序需要使用的数据类型的实例。
    
    (2)SOAP RPC 表示远程过程调用和应答的协定。
    
    (4)SOAP绑定(binding),使用底层协议交换信息。
    
     
    
    (1)请求的协议体
    
    POST /weather HTTP/1.1
    
    Accept: text/xml, multipart/related
    
    Content-Type: text/xml; charset=utf-8
    
    SOAPAction: "http://weather.itheima.com/WeatherInterface/getWeatherByCityNameRequest"
    
    User-Agent: JAX-WS RI 2.2.4-b01
    
    Host: 127.0.0.1:54321
    
    Connection: keep-alive
    
    Content-Length: 235
    
    <?xml version="1.0" ?>
    
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    
           <S:Body>
    
                 <ns2:getWeatherByCityName xmlns:ns2="http://weather.itheima.com">
    
                      <cityName>北京</cityName>
    
                 </ns2:getWeatherByCityName>
    
           </S:Body>
    
    </S:Envelope>
    
     
    
    (2)响应的协议体
    
    HTTP/1.1 200 OK
    
    Transfer-encoding: chunked
    
    Content-type: text/xml; charset=utf-8
    
    Date: Fri, 09 Oct 2015 07:23:29 GMT
    
    <?xml version="1.0" ?>
    
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    
             <S:Body>
    
                     <ns2:getWeatherByCityNameResponse xmlns:ns2="http://weather.itheima.com">
    
                               <WeatherInfo>今天风很大</WeatherInfo>
    
                     </ns2:getWeatherByCityNameResponse>
    
             </S:Body>
    
    </S:Envelope>
    
     
    
    (3)发布基于soap1.2协议的服务
    
    在SEI(service endpoint interface 服务端点接口)实现类上添加如下注解
    
    @BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
    
    发布基于soap1.2协议的服务,需要jax-ws包要求2.2.8以上版本。
    
     
    
    (4)soap1.2请求的协议体
    
    POST /weather HTTP/1.1
    
    Accept: application/soap+xml, multipart/related
    
    Content-Type: application/soap+xml; charset=utf-8;
    
    action="http://weather.itheima.com/WeatherInterface/getWeatherByCityNameRequest"
    
    User-Agent: JAX-WS RI 2.2.4-b01
    
    Host: 127.0.0.1:54321
    
    Connection: keep-alive
    
    Content-Length: 233
    
    <?xml version="1.0" ?>
    
    <S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
    
                  <S:Body>
    
                        <ns2:getWeatherByCityName xmlns:ns2="http://weather.itheima.com">
    
                              <cityName>北京</cityName>
    
                        </ns2:getWeatherByCityName>
    
                  </S:Body>
    
    </S:Envelope>
    
     
    
    (5)soap1.2响应的协议体
    
    HTTP/1.1 200 OK
    
    Transfer-encoding: chunked
    
    Content-type: application/soap+xml; charset=utf-8
    
    Date: Fri, 09 Oct 2015 07:54:53 GMT
    
    <?xml version='1.0' encoding='UTF-8'?>
    
    <S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
    
            <S:Body>
    
                      <ns2:getWeatherByCityNameResponse xmlns:ns2="http://weather.itheima.com">
    
                              <WeatherInfo>今天风很大</WeatherInfo>
    
                      </ns2:getWeatherByCityNameResponse>
    
            </S:Body>
    
    </S:Envelope>
    
     
    
    2.WSDL
    
         WSDL(Web Service Description Language),是一个用来描述Web服务(Web Service)和说明如何与Web服务通信的XML语言。因为是基于XML的,
    所以WSDL既是机器可阅读的,又是人可阅读的,这将是一个很大的好处。
    
    
    
    (1)wsdl的阅读方法
    
    是从下往上读。
    
    每个wsdl有且只有一个Service节点。
    
    1、先找Service节点
    
    2、Service节点中找port节点。每个port对应一个PortType。
    
    3、Port节点对应一binding节点。每个binding节点对应一个PortType
    
    4、PortType中有operation 节点就是服务的方法。
    
    5、operation 中有Input(参数)和output(返回值)
    
    6、Input(参数)和output(返回值)对应message节点
    
    7、Message对应element节点。Element节点对应complexType节点描述了参数及返回值的数据类型。
    
     
    
    (2)使用注解规范wsdl
    
    @WebService: 定义服务,在public class上边。
    
       targetNamespace:指定命名空间。
    
       name:portType的名称。
    
       portName:port的名称。
    
      serviceName:服务名称。
    
     
    
    @WebResult:定义返回值。
    
       name:返回结果值的名称。
    
     
    
    @WebParam:定义参数。
    
       name:指定参数的名称。
    
     
    
    @WebMethod
    
    exclude:排除指定的方法。
    
    默认情况下,SEI实现类中所以的public方法会发布成服务方法。
    
    如果不想把public方法发布成服务方法,需要使用@WebMethod注解。把此方法排除。在实现类中至少有一个方法发布为服务方法。
    
    
     
    
    
    
    http://127.0.0.1:12345/weather?wsdl
    
    
    
    
    
    
     
    
    http://127.0.0.1:12345/weather?xsd=1
    




    作用: 通过注解,可以更加形像的描述Web服务。对自动生成的wsdl文档进行修改,为使用者提供一个更加清晰的wsdl文档。 当修改了WebService注解之后,会影响客户端生成的代码。调用的方法名和参数名也发生了变化。 3.UDDI UDDI 是一种目录服务,通过它,企业可注册并搜索 Web services。企业将自己提供的Web Service注册在UDDI,也可以使用别的企业在UDDI注册的web service服务,从而达到资源共享。 UDDI旨在将全球的webservcie资源进行共享,促进全球经济合作。 但是使用webservice并不是必须使用UDDI,因为用户通过WSDL知道了web service的地址,可以直接通过WSDL调用webservice。(现已废弃)
  • 相关阅读:
    ubuntu video and audio
    js type
    jumpserver 堡垒机环境搭建
    ubuntu dnsmasq
    bind--dns-docker---[nslookup/dig]
    java maven scope compile,provide,system,test,runtime
    docker install and minikube install
    nginx break-circus orange api-gateway
    一个IP能建立的最大连接数是多少?
    Docker 在6.4上安装
  • 原文地址:https://www.cnblogs.com/mr-wuxiansheng/p/6444353.html
Copyright © 2020-2023  润新知