2019-03-13 WebService入门学习

1 什么是WebService

它是一种构建应用程序的普遍模型,可以在任何支持网络通信的操作系统中实施运行;它是一种新的web应用程序分支,是自包含、自描述、模块化的应用,可以发布、定位、通过web调用。Web Service是一个应用组件,它逻辑性的为其他应用程序提供数据与服务.各应用程序通过网络协议和规定的一些标准数据格式(Http,XML,Soap)来访问Web Service,通过Web Service内部执行得到所需结果.Web Service可以执行从简单的请求到复杂商务处理的任何功能。一旦部署以后,其他Web Service应用程序可以发现并调用它部署的服务。

2 关键技术和规则

在构建和使用Web Service时,主要用到以下几个关键的技术和规则:

2.1 XML:描述数据的标准方法.

可扩展的标记语言(XML)是Web service平台中表示数据的基本格式。除了易于建立和易于分析外,XML主要的优点在于它既是平台无关的,又是厂商无关的。无关性是比技术优越性更重要的:软件厂商是不会选择一个由竞争对手所发明的技术的。

2.2 SOAP:表示信息交换的协议.

SOAP是web service的标准通信协议,SOAP为simple object access protocoll的缩写,简单对象访问协议. 它是一种标准化的传输消息的XML消息格式。

2.3 WSDL:Web服务描述语言

WSDL的全称是web service Description Language,是一种基于XML格式的关于web服务的描述语言。其主要目的在于web service的提供者将自己的web服务的所有相关内容,如所提供的服务的传输方式,服务方法接口,接口参数,服务路径等,生成相应的完全文档,发布给使用者。使用者可以通过这个WSDL文档,创建相应的SOAP请求消息,通过HTTP传递给webservice提供者;web服务在完成服务请求后,将SOAP返回消息传回请求者,服务请求者再根据WSDL文档将SOAP返回消息解析成自己能够理解的内容。

2.4 UDDI:通用描述、发现与集成,它是一种独立于平台的,基于XML语言的用于在互联网上描述商务的协议。

将web service进行UDDI注册发布,UDDI是一种创建注册表服务的规范,以便大家将自己的web service进行注册发布供使用者查找.然而当服务提供者想将自己的web service向全世界公布,以便外部找到其服务时,那么服务提供者可以将自己的web service注册到相应的UDDI商用注册网站,目前全球有IBM等4家UDDI商用注册网站。因为WSDL文件中已经给定了web service的地址URI,外部可以直接通过WSDL提供的URI进行相应的web service调用。所以UDDI并不是一个必需的web service组件,服务方完全可以不进行UDDI的注册。

3 常用标签释义

3.1 服务端

3.1.1 发布本服务器内部服务端口

@WebService
public interface InstrumentServiceIntf {
    @WebMethod
    List<InstrumentInfoBean> getEquipmentSearch(Context context,
            final @WebParam(name = "name") String name);
}

实现类

@SuppressWarnings("restriction")
@WebService(name = "instrument", 
serviceName = "InstrumentServiceImpl", 
targtNamespace = "http://com.jiuqi.dna.gams.GXH.DXYQ.webservice.intf/", 
endpointInterface = "com.jiuqi.dna.gams.GXH.DXYQ.webservice.intf.InstrumentServiceIntf")
public class InstrumentServiceImpl extends Service implements InstrumentServiceIntf{}

3.1.2 发布其他服务器内部服务端口

package com.jiuqi.dna.gams.gxh.dxyq.webservice.intf;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

/**
 * This class was generated by Apache CXF 2.3.3
 * 2019-01-15T15:37:41.874+08:00
 * Generated source version: 2.3.3
 * 
 */
 
@WebService(targetNamespace = "http://intf.webservice.DXYQ.GXH.gams.dna.jiuqi.com/",
name = "InstrumentServiceIntf")
@XmlSeeAlso({ObjectFactory.class})
public interface InstrumentServiceIntf {

 
    @WebMethod
    @RequestWrapper(localName = "updateSelfTestStatus", 
targetNamespace = "http://intf.webservice.DXYQ.GXH.gams.dna.jiuqi.com/", 
className = "com.jiuqi.dna.gams.gxh.dxyq.webservice.intf.UpdateSelfTestStatus")
    @ResponseWrapper(localName = "updateSelfTestStatusResponse", 
targetNamespace = "http://intf.webservice.DXYQ.GXH.gams.dna.jiuqi.com/", 
className = "com.jiuqi.dna.gams.gxh.dxyq.webservice.intf.UpdateSelfTestStatusResponse")
    @WebResult(name = "return", targetNamespace = "")
    public int updateSelfTestStatus(
        @WebParam(name = "credictCardInfo", targetNamespace = "")
        java.lang.String credictCardInfo
    );

3.2 客户端


/*
 * 
 */

package intf.webservice.dxyq.gxh.gams.dna.jiuqi.com;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceFeature;
import com.jiuqi.dna.gams.gxh.dxyq.webservice.intf.InstrumentServiceIntf;
import javax.xml.ws.Service;

/**
 * This class was generated by Apache CXF 2.3.3
 * 2019-01-15T15:37:41.942+08:00
 * Generated source version: 2.3.3
 * 
 */


@WebServiceClient(name = "InstrumentServiceImpl", 
//                  wsdlLocation = "http://www.yqsbgl.ynu.edu.cn/dna_ws/instrument?wsdl",
                    wsdlLocation = "http://192.168.128.1:9797/dna_ws/instrument?wsdl",
                  targetNamespace = "http://com.jiuqi.dna.gams.GXH.DXYQ.webservice.intf/") 
public class InstrumentServiceImpl extends Service {

    public final static URL WSDL_LOCATION;

    public final static QName SERVICE = new QName("http://com.jiuqi.dna.gams.GXH.DXYQ.webservice.intf/", "InstrumentServiceImpl");
    public final static QName InstrumentPort = new QName("http://com.jiuqi.dna.gams.GXH.DXYQ.webservice.intf/", "instrumentPort");
    static {
        URL url = null;
        try {
//          url = new URL("http://www.yqsbgl.ynu.edu.cn/dna_ws/instrument?wsdl");
            url = new URL("http://192.168.128.1:9797/dna_ws/instrument?wsdl");
            
        } catch (MalformedURLException e) {
            System.err.println("Can not initialize the default wsdl from http://www.yqsbgl.ynu.edu.cn/dna_ws/instrument?wsdl");
            // e.printStackTrace();
        }
        WSDL_LOCATION = url;
    }

    public InstrumentServiceImpl(URL wsdlLocation) {
        super(wsdlLocation, SERVICE);
    }

    public InstrumentServiceImpl(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public InstrumentServiceImpl() {
        super(WSDL_LOCATION, SERVICE);
    }
    
    //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
    //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
    //compliant code instead.
    public InstrumentServiceImpl(WebServiceFeature ... features) {
        super(WSDL_LOCATION, SERVICE, features);
    }

    //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
    //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
    //compliant code instead.
    public InstrumentServiceImpl(URL wsdlLocation, WebServiceFeature ... features) {
        super(wsdlLocation, SERVICE, features);
    }

    //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
    //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
    //compliant code instead.
    public InstrumentServiceImpl(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) {
        super(wsdlLocation, serviceName, features);
    }

    /**
     * 
     * @return
     *     returns InstrumentServiceIntf
     */
    @WebEndpoint(name = "instrumentPort")
    public InstrumentServiceIntf getInstrumentPort() {
        return super.getPort(InstrumentPort, InstrumentServiceIntf.class);
    }

    /**
     * 
     * @param features
     *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
     * @return
     *     returns InstrumentServiceIntf
     */
    @WebEndpoint(name = "instrumentPort")
    public InstrumentServiceIntf getInstrumentPort(WebServiceFeature... features) {
        return super.getPort(InstrumentPort, InstrumentServiceIntf.class, features);
    }

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容