WSDL4J解析WSDL文件方法

摘要:
使用wsdl4j解析WSDL文件工具:wsdl4j1.6解析WSDL文件是axis1.4 WSDL文件的服务WSDL文件:---------以下两个程序是用wsdl4j:Program 1:viewplaincopytoclipboardprint编写的?

利用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.     
  64. }catch(WSDLException e){e.printStackTrace();}   
  65. }  
  66. }  

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

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

免责声明:文章转载自《WSDL4J解析WSDL文件方法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Iframe父子窗口之间的跨域事件调用和传值netstat命令下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

matlab中plot使用方法

MATLAB有非常强的图形功能,能够方便地实现数据的视觉化。强大的计算功能与图形功能相结合为MATLAB在科学技术和教学方面的应用提供了更加广阔的天地。以下着重介绍二维图形的画法,对三维图形仅仅作简单叙述。 5.1 二维图形的绘制 5.1.1 基本形式 二维图形的绘制是MATLAB语言图形处理的基础,MATLAB最经常使用的画二维图形的命令是p...

基础方法或属性: 列表,元组,字典,字符串,集合及内置函数等(注:只有英文名)

列表 list append clear copy count extend index insert pop remove reverse sort 元组 tuple count index 字典 dict clear copy fromkeys get items keys pop popitem setdefault update values 字...

Android基于ksoap2调用WCF服务(二):Android篇

上一篇通过一个非常简单的例子,完成了一个WCF的服务。接下来介绍一下Android端。 Android端调用WCF,采用基于ksoap2包来实现。 下载地址(这个需要fan qiang访问,你们懂的):https://code.google.com/p/ksoap2-android/ 我用的3.3.0版本,我传到csdn上,上面地址如果不能访问,可以用这个...

学会使用Web Service下(客户端访问)/(服务器端访问)

http://www.cnblogs.com/ruihua/archive/2007/10/28/940287.html http://www.cnblogs.com/ruihua/archive/2007/10/28/939932.html学会使用Web Service上(服务器端访问)     关于什么是Web Service,相信在很多地方都会有介绍...

C# 通过模拟http请求来调用soap、wsdl

C#调用webservice的方法很多,我说的这种通过http请求模拟来调用的方式是为了解决C#调用java的远程API出现各种不兼容问题。 由于远程API不在我们的控制下,我们只能修改本地的调用代码来适应远程API。 在以上情况下,我们就通过模拟http请求来去调用webservice。 首先,我们要分析调用端口时,我们发送出去的数据。 先抓个包看看,这...

WebService基础入门(转)

一.概念: 1、WebService,顾名思义就是基于Web的服务。它使用Web(HTTP)方式,接收和响应外部系统的某种请求。从而实现远程调用. 2、我们可以调用互联网上查询天气信息Web服务,然后将它嵌入到我们的程序(C/S或B/S程序)当中来,当用户从我们的网点看到天气信息时,他会认为我们为他提供了很多的信息服务,但其实我们什么也没有做,只是简单调用...