利用wsdl4j解析WSDL文件

工具:wsdl4j1.6

解析wsdl文件是axis1.4的服务wsdl文件

wsdl文件:

<?xml version="1.0" encoding="UTF-8" ?>
-  <wsdl:definitions targetNamespace="http://localhost:8080/axis/services/SayHelloService
xmlns:apachesoap="http://xml.apache.org/xml-soap
xmlns:impl="http://localhost:8080/axis/services/SayHelloService
xmlns:intf="http://localhost:8080/axis/services/SayHelloService
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <!--

WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)

-->

- <wsdl:message name="sayHelloResponse">
  <wsdl:part name="sayHelloReturn" type="xsd:string" />
</wsdl:message>
- <wsdl:message name="sayHelloRequest">
  <wsdl:part name="name" type="xsd:string" />
</wsdl:message>
- <wsdl:portType name="SayHello">
- <wsdl:operation name="sayHello" parameterOrder="name">
  <wsdl:input message="impl:sayHelloRequest" name="sayHelloRequest" />
  <wsdl:output message="impl:sayHelloResponse" name="sayHelloResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="SayHelloServiceSoapBinding" type="impl:SayHello">
  <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="sayHello">
  <wsdlsoap:operation soapAction="" />
- <wsdl:input name="sayHelloRequest">
  <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://hello.com" use="encoded" />
</wsdl:input>
- <wsdl:output name="sayHelloResponse">
  <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8080/axis/services/SayHelloService" use="encoded" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
-  <wsdl:service name="SayHelloService">
 - <wsdl:port binding="impl:SayHelloServiceSoapBinding" name="SayHelloService"> 
  <wsdlsoap:address location="http://localhost:8080/axis/services/SayHelloService" />
</wsdl:port>
</wsdl:service>

</wsdl:definitions>

下面是两个程序wsdl4j编写:

程序1:

  1. package com.wxm;
  2. import javax.wsdl.*;
  3. import javax.wsdl.factory.*;
  4. import javax.wsdl.xml.*;
  5. public class ReadWsdl {
  6. public static void main(String[]args)
  7. {
  8. try{
  9. WSDLFactory factory=WSDLFactory.newInstance();
  10. WSDLReader reader=factory.newWSDLReader();
  11. reader.setFeature("javax.wsdl.verbose",true);
  12. reader.setFeature("javax.wsdl.importDocuments",true);
  13. Definition def=reader.readWSDL("http://localhost:8080/axis/services/SayHelloService?wsdl");
  14. WSDLWriter writer=factory.newWSDLWriter();
  15. writer.writeWSDL(def, System.out);
  16. }catch(WSDLException e){e.printStackTrace();}
  17. }
  18. }

程序2:

  1. package com.wxm;
  2. import javax.wsdl.*;
  3. import javax.wsdl.extensions.*;
  4. import javax.wsdl.factory.*;
  5. import javax.wsdl.xml.*;
  6. import javax.xml.namespace.QName;
  7. import java.util.*;
  8. import org.w3c.dom.*;
  9. public class NavigatingWSDL {
  10. public static void main(String[]args)
  11. {
  12. try{
  13. WSDLFactory factory=WSDLFactory.newInstance();
  14. WSDLReader reader=factory.newWSDLReader();
  15. reader.setFeature("javax.wsdl.verbose",true);
  16. reader.setFeature("javax.wsdl.importDocuments",true);
  17. Definition def=reader.readWSDL("http://localhost:8080/axis/services/SayHelloService?wsdl");
  18. //解析服务名
  19. System.out.println("----------");
  20. System.out.println("nService Name:");
  21. String tns="http://localhost:8080/axis/services/SayHelloService";
  22. Service service =def.getService(new QName(tns,"SayHelloService"));
  23. System.out.println(service.getQName().getLocalPart());
  24. //解析接口方法名
  25. System.out.println("nOperation Name:");
  26. Port port =service.getPort("SayHelloService");
  27. Binding binding=port.getBinding();
  28. PortType portType=binding.getPortType();
  29. List operations=portType.getOperations();
  30. Iterator operIter=operations.iterator();
  31. while(operIter.hasNext())
  32. {
  33. Operation operation=(Operation)operIter.next();
  34. if(!operation.isUndefined())
  35. {System.out.println(operation.getName()) ;}
  36. }
  37. //解析消息,输入输出
  38. System.out.println("nMessages:");
  39. Map messages=def.getMessages();
  40. Iterator msgIter=messages.values().iterator();
  41. while(msgIter.hasNext())
  42. {
  43. Message msg=(Message)msgIter.next();
  44. if(!msg.isUndefined())
  45. {
  46. System.out.println(msg.getQName().getLocalPart());
  47. Iterator partIter=msg.getParts().values().iterator();
  48. while(partIter.hasNext())
  49. {
  50. Part part=(Part) partIter.next();
  51. System.out.print("parameter name:"+part.getName()+"t");
  52. System.out.println("parameter type:"+part.getTypeName().getLocalPart());
  53. }
  54. }
  55. }
  56. //解析服务地址
  57. System.out.println("nService location:");
  58. List l=port.getExtensibilityElements();
  59. ExtensibilityElement element=(ExtensibilityElement) l.get(0);
  60. String s=element.toString();
  61. System.out.println(s.substring(s.indexOf("location")));
  62. System.out.println("---------");
  63. }catch(WSDLException e){e.printStackTrace();}
  64. }
  65. }

可以解析出wsdl文件的服务名,操作接口名,服务地址等

转:http://blog.sina.com.cn/s/blog_5ee36ce70100nk97.html

WSDL4J解析WSDL文件方法的更多相关文章

  1. c++ 读取并解析excel文件方法

    用Cocos开发模型特效工具编辑器,跨Mac和windows,当中有个需求是读取并解析excel文件,但网上的查找的例子几乎都只能是在windows下面使用,再或者是命令行脚本之类的.于是,自己写了一 ...

  2. 图解SOAPUI解析WSDL文件

    本文链接:https://blog.csdn.net/qq_16234613/article/details/53143279 新建项目 添加WSDL文件 查看方法 查看XML格式 运行测试  

  3. axis2--生成的wsdl文件方法的参数问题

    我是一个使用axis2的新手,发现一个问题: * axis2生成的wsdl文件中关于提供服务的方法,其参数名称丢失,会变成args0 * , 原因: axis2 无法从java字节码中获取关于方法签名 ...

  4. android解析xml文件方法之一-----DOM

    Hello.xml文件 <dict num="219" id="219" name="219"> <key>hell ...

  5. So easy Webservice 5.WSDL 文件说明

    WSDL – WebService Description Language – Web服务描述语言 通过XML形式说明服务在什么地方-地址. 通过XML形式说明服务提供什么样的方法 – 如何调用. ...

  6. Java中使用DOM4J来生成xml文件和解析xml文件

    一.前言 现在有不少需求,是需要我们解析xml文件中的数据,然后导入到数据库中,当然解析xml文件也有好多种方法,小编觉得还是DOM4J用的最多最广泛也最好理解的吧.小编也是最近需求里遇到了,就来整理 ...

  7. 学习 WebService 第二步:知识准备——WSDL文件解析

    原文地址:https://www.cnblogs.com/yzw23333/p/7245104.html Web service中一个 WSDL 对应一个 web service地址. 可以想象成一个 ...

  8. ACEXML解析XML文件——我是如何学习并在短时间内掌握一个库的使用方法的

    最近做的C++项目中需要使用xml文件保存一些信息,程序启动时会读取这些信息.最终经过主程的评测,决定使用ACEXML库来读取解析XML文件. 好吧,至于为什么选择ACEXML库,我就不说了.既然选择 ...

  9. 遍历文件 创建XML对象 方法 python解析XML文件 提取坐标计存入文件

    XML文件??? xml即可扩展标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. 里面的标签都是可以随心所欲的按照他的命名规则来定义的,文件名为roi.xm ...

随机推荐

  1. 在/etc/crondtab中添加定时任务注意事项

    1 要添加用户名 2 要重启定时任务服务

  2. json数据格式 与 for in

    格式一: var json1={ name:'json', age:'23' }; json1.name='金毛'; 格式二: (比较安全)  属性名字里有空格或者有连字符‘-’或者有保留字例如‘fo ...

  3. memory bist lib

    model NVIC_REG6T_1024x32(resetb,margin,clk,en,we,addr,d,q) ( bist_definition( clock clk high; chip_e ...

  4. laravel中对加载进行优化

    在laravel中的模型与模型之间创建好关联关系会比较方便的方法 但是我们为了方便,有时也会忽略一些东西,比如: 我们在控制器中把整个一个文章对象传到了模板页面 在一次for循环下, 我们对数据进行了 ...

  5. 数据结构( Pyhon 语言描述 ) — — 第8章:队列

    队列概览 队列是线性的集合 队列的插入限制在队尾,删除限制在队头.支持先进先出协议( FIFIO, first-in first-out ) 两个基本操作 add:在队尾添加一项 pop:从队头弹出一 ...

  6. (转)UITextField

    //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, ...

  7. LeetCode(111) Minimum Depth of Binary Tree

    题目 Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the s ...

  8. f-Strings:一种改进Python格式字符串的新方法

    好消息是,F字符串在这里可以节省很多的时间.他们确实使格式化更容易.他们自Python 3.6开始加入标准库.您可以在PEP 498中阅读所有内容. 也称为“格式化字符串文字”,F字符串是开头有一个f ...

  9. Hive中文注释乱码解决方案(2)

    本文来自网易云社区 作者:王潘安 执行阶段 launchTask    回到Driver类的runInternal方法,看以下执行过程.在runInternal方法中,执行过程调用了execute方法 ...

  10. Yii2.0 添加分类category model类

    <?php namespace app\models; use yii\db\ActiveRecord; use Yii; use yii\helpers\ArrayHelper; class ...