当前位置: 首页 > news >正文

java-工具-Webservice wsdl解析

原文链接:http://www.cnblogs.com/coshaho/p/5689738.html
wsdl解析

首先必然是理解第三方webservice的接口描述,也就是解析wsdl文件。wsdl文件是webservice服务接口描述文档,一个wsdl文件可以包含多个接口,一个接口可以包含多个方法。

public class WsdlInfo 
{
    private String wsdlName;

    private List<InterfaceInfo> interfaces;

    /**
     * coshaho
     * @param path  wsdl地址
     * @throws Exception
     */
    public WsdlInfo(String path) throws Exception
    {
        WProject project = new WProject();
        WsdlInterface[] wsdlInterfaces = WsdlImporter.importWsdl( project, path );
        this.wsdlName = path;
        if(null != wsdlInterfaces)
        {    
            List<InterfaceInfo> interfaces = new ArrayList<InterfaceInfo>();
            for(WsdlInterface wsdlInterface : wsdlInterfaces)
            {
                InterfaceInfo interfaceInfo = new InterfaceInfo(wsdlInterface);
                interfaces.add(interfaceInfo);
            }
            this.interfaces = interfaces;
        }
    }

    public String getWsdlName() {
        return wsdlName;
    }

    public void setWsdlName(String wsdlName) {
        this.wsdlName = wsdlName;
    }

    public List<InterfaceInfo> getInterfaces() {
        return interfaces;
    }

    public void setInterfaces(List<InterfaceInfo> interfaces) {
        this.interfaces = interfaces;
    }
}
public class InterfaceInfo 
{
    private String interfaceName;

    private List<OperationInfo> operations;

    private String[] adrress;

    public InterfaceInfo(WsdlInterface wsdlInterface)
    {
        this.interfaceName = wsdlInterface.getName();

        this.adrress = wsdlInterface.getEndpoints();

        int operationNum = wsdlInterface.getOperationCount();
        List<OperationInfo> operations = new ArrayList<OperationInfo>();

        for(int i = 0; i < operationNum; i++)
        {
            WsdlOperation operation = ( WsdlOperation )wsdlInterface.getOperationAt( i );
            OperationInfo operationInfo = new OperationInfo(operation);
            operations.add(operationInfo);
        }

        this.operations = operations;
    }

    public String getInterfaceName() {
        return interfaceName;
    }

    public void setInterfaceName(String interfaceName) {
        this.interfaceName = interfaceName;
    }

    public List<OperationInfo> getOperations() {
        return operations;
    }

    public void setOperations(List<OperationInfo> operations) {
        this.operations = operations;
    }

    public String[] getAdrress() {
        return adrress;
    }

    public void setAdrress(String[] adrress) {
        this.adrress = adrress;
    }
}
public class OperationInfo 
{
    private String operationName;

    private String requestXml;

    private String responseXml;

    public OperationInfo(WsdlOperation operation)
    {
        operationName = operation.getName();
        requestXml = operation.createRequest( true );
        responseXml = operation.createResponse(true);    
    }

    public String getOperationName() {
        return operationName;
    }

    public void setOperationName(String operationName) {
        this.operationName = operationName;
    }

    public String getRequestXml() {
        return requestXml;
    }

    public void setRequestXml(String requestXml) {
        this.requestXml = requestXml;
    }

    public String getResponseXml() {
        return responseXml;
    }

    public void setResponseXml(String responseXml) {
        this.responseXml = responseXml;
    }
}
public class WSDLParseTest 
{
    public static void main(String[] args) throws Exception
    {
        String url = "http://webservice.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx?wsdl";
        WsdlInfo wsdlInfo = new WsdlInfo(url);
        System.out.println("WSDL URL is " + wsdlInfo.getWsdlName());

        for(InterfaceInfo interfaceInfo : wsdlInfo.getInterfaces())
        {
            System.out.println("Interface name is " + interfaceInfo.getInterfaceName());
            for(String ads : interfaceInfo.getAdrress())
            {
                System.out.println("Interface address is " + ads);
            }
            for(OperationInfo operation : interfaceInfo.getOperations())
            {
                System.out.println("operation name is " + operation.getOperationName());
                System.out.println("operation request is ");
                System.out.println("operation request is " + operation.getRequestXml());
                System.out.println("operation response is ");
                System.out.println(operation.getResponseXml());
            }
        }
    }
}
WSDL URL is http://webservice.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx?wsdl
Interface name is ChinaOpenFundWSSoap12
Interface address is http://webservice.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx
operation name is getFundCodeNameDataSet
operation request is 
operation request is <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/">
   <soap:Header/>
   <soap:Body>
      <web:getFundCodeNameDataSet/>
   </soap:Body>
</soap:Envelope>
operation response is 
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <soap:Header/>
   <soap:Body>
      <web:getFundCodeNameDataSetResponse>
         <!--Optional:-->
         <web:getFundCodeNameDataSetResult>
            <xs:schema>
               <!--Ignoring type [{http://www.w3.org/2001/XMLSchema}schema]-->
            </xs:schema>
            <!--You may enter ANY elements at this point-->
         </web:getFundCodeNameDataSetResult>
      </web:getFundCodeNameDataSetResponse>
   </soap:Body>
</soap:Envelope>
operation name is getFundCodeNameString
operation request is 
operation request is <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/">
   <soap:Header/>
   <soap:Body>
      <web:getFundCodeNameString/>
   </soap:Body>
</soap:Envelope>
operation response is 
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/">
   <soap:Header/>
   <soap:Body>
      <web:getFundCodeNameStringResponse>
         <!--Optional:-->
         <web:getFundCodeNameStringResult>
            <!--Zero or more repetitions:-->
            <web:string>?</web:string>
         </web:getFundCodeNameStringResult>
      </web:getFundCodeNameStringResponse>
   </soap:Body>
</soap:Envelope>
operation name is getOpenFundDataSet
operation request is 
operation request is <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/">
   <soap:Header/>
   <soap:Body>
      <web:getOpenFundDataSet>
         <!--Optional:-->
         <web:userID>?</web:userID>
      </web:getOpenFundDataSet>
   </soap:Body>
</soap:Envelope>
operation response is 
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <soap:Header/>
   <soap:Body>
      <web:getOpenFundDataSetResponse>
         <!--Optional:-->
         <web:getOpenFundDataSetResult>
            <xs:schema>
               <!--Ignoring type [{http://www.w3.org/2001/XMLSchema}schema]-->
            </xs:schema>
            <!--You may enter ANY elements at this point-->
         </web:getOpenFundDataSetResult>
      </web:getOpenFundDataSetResponse>
   </soap:Body>
</soap:Envelope>

相关文章:

  • 重定向 管道
  • [ZigBee] 16、Zigbee协议栈应用(二)——基于OSAL的无线控制LED闪烁分析(下)
  • 微信公众号开发小记——5.python微信红包
  • Android 开发之布局细节对比:Gravity相关
  • 纯Html+Ajax和JSP两者对比的个人理解
  • LEAVE LIST-PROCESSING和LEAVE TO LIST-PROCESSING事件的作用
  • 开根号研究
  • CCIE学习笔记 ----BGP
  • 什么是内存泄漏
  • Log4Net使用指南 - sema - 博客园
  • CentOS运行级别和开机过程
  • 道格拉斯-普克 抽稀算法 附javascript实现
  • jQuery效果-淡入淡出
  • AWSCLI安装及使用
  • iOS - AsyncSocket 的使用
  • 【159天】尚学堂高琪Java300集视频精华笔记(128)
  • angular2 简述
  • CSS实用技巧
  • magento 货币换算
  • Mysql数据库的条件查询语句
  • Next.js之基础概念(二)
  • Nodejs和JavaWeb协助开发
  • Vue小说阅读器(仿追书神器)
  • windows下mongoDB的环境配置
  • 百度贴吧爬虫node+vue baidu_tieba_crawler
  • 彻底搞懂浏览器Event-loop
  • 第三十一到第三十三天:我是精明的小卖家(一)
  • 好的网址,关于.net 4.0 ,vs 2010
  • 看域名解析域名安全对SEO的影响
  • 目录与文件属性:编写ls
  • 前端面试题总结
  • 前言-如何学习区块链
  • 实战|智能家居行业移动应用性能分析
  • 学习笔记DL002:AI、机器学习、表示学习、深度学习,第一次大衰退
  • 选择阿里云数据库HBase版十大理由
  • 昨天1024程序员节,我故意写了个死循环~
  • ​​​​​​​ubuntu16.04 fastreid训练过程
  • #### go map 底层结构 ####
  • #HarmonyOS:基础语法
  • #QT(智能家居界面-界面切换)
  • #使用清华镜像源 安装/更新 指定版本tensorflow
  • $$$$GB2312-80区位编码表$$$$
  • (4) PIVOT 和 UPIVOT 的使用
  • (c语言版)滑动窗口 给定一个字符串,只包含字母和数字,按要求找出字符串中的最长(连续)子串的长度
  • (Demo分享)利用原生JavaScript-随机数-实现做一个烟花案例
  • (南京观海微电子)——COF介绍
  • (四) 虚拟摄像头vivi体验
  • (四)汇编语言——简单程序
  • (转)Groupon前传:从10个月的失败作品修改,1个月找到成功
  • (转)创业的注意事项
  • ..thread“main“ com.fasterxml.jackson.databind.JsonMappingException: Jackson version is too old 2.3.1
  • .NET 使用 JustAssembly 比较两个不同版本程序集的 API 变化
  • .NET基础篇——反射的奥妙
  • [ vulhub漏洞复现篇 ] JBOSS AS 5.x/6.x反序列化远程代码执行漏洞CVE-2017-12149
  • []常用AT命令解释()