生成的WSDL怎么引用到项目 最近要做一个网关开发,移动给的接口是webservice,但是只给了wsdl文件。 该怎么把这些文件导入到项目中呢?以前做.NET开发的是很直接引用远程的webservice地址就行。但这次用java开发,不是给我的webservice地址,而是生成的wsdl。谢谢各位了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 a:apache-cxf-2.1.1的bin目录下有wsdl2java工具,可以将wsdl生成java文件,官网上有详细的使用方法。生成后,再把生成的代码拷入Eclipse项目即可。b:<?xml version="1.0" ?><wsdl:definitions targetNamespace="urn:listing4" xmlns:tns="urn:listing4" xmlns:listing5="urn:listing5" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> <wsdl:import namespace="urn:listing5" location="listing5.wsdl"/> <wsdl:types> <xsd:schema targetNamespace="urn:listing4" xmlns:listing5="urn:listing5" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:import namespace="http://www.w3.org/2001/XMLSchema"/> <xsd:complexType name="Address"> <xsd:sequence> <xsd:element name="streetNum" type="xsd:int"/> <xsd:element name="streetName" type="xsd:string"/> <xsd:element name="city" type="xsd:string"/> <xsd:element name="state" type="xsd:string"/> <xsd:element name="phone" type="listing5:Phone" /> </xsd:sequence> </xsd:complexType> </xsd:schema> </wsdl:types> <wsdl:message name="GetAddressRequest"> <wsdl:part name="name" type="xsd:string"/> </wsdl:message> <wsdl:message name="GetAddressResponse"> <wsdl:part name="address" type="tns:Address"/> </wsdl:message> <wsdl:message name="GetPhoneRequest"> <wsdl:part name="name" type="xsd:string"/> </wsdl:message> <wsdl:message name="GetPhoneResponse"> <wsdl:part name="phone" type="listing5:Phone" /> </wsdl:message> <wsdl:portType name="AddressBook"> <wsdl:operation name="getAddress"> <wsdl:input message="tns:GetAddressRequest"/> <wsdl:output message="tns:GetAddressResponse"/> </wsdl:operation> <wsdl:operation name="getPhone"> <wsdl:input message="tns:GetPhoneRequest"/> <wsdl:output message="tns:GetPhoneResponse"/> </wsdl:operation> </wsdl:portType></wsdl:definitions>清单 5. Phone 模式的 WSDL 文件<?xml version="1.0" ?> <wsdl:definitions targetNamespace="urn:listing5" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <wsdl:types> <xsd:schema targetNamespace="urn:listing5" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:import namespace="http://www.w3.org/2001/XMLSchema"/> <xsd:complexType name="Phone"> <xsd:sequence> <xsd:element name="areaCode" type="xsd:int"/> <xsd:element name="exchange" type="xsd:int"/> <xsd:element name="number" type="xsd:int"/> </xsd:sequence> </xsd:complexType> </xsd:schema> </wsdl:types></wsdl:definitions> Axis开发webservices接口详细步骤1. Java1.6+Tomcat5.5+MyEclipse+Axis1.4Java环境就不用多说(1).从www.apache.org上下载axis ,我下载的是axis-bin-1_4(2). 解压缩到D盘(根据自己需要)(3).环境变量: 变量名:AXIS_HOME 值:D:\axis-1_4变量名:AXIS_LIB 值:%AXIS_HOME%\WEB-INF\lib变量名:AXISCLASSPATH值:%AXIS_LIB%\axis.jar;%AXIS_LIB%\axis-ant.jar;%AXIS_LIB%\axis-schema.jar;%AXIS_LIB%\commons-discovery-0.2.jar;%AXIS_LIB%\commons-logging-1.0.4.jar;%AXIS_LIB%\jaxrpc.jar;%AXIS_LIB%\log4j-1.2.8.jar;%AXIS_LIB%\saaj.jar;%AXIS_LIB%\wsdl4j-1.5.1.jar; %AXIS_LIB%\activation.jar;%AXIS_LIB%\mail.jar;%AXIS_LIB%\xmlsec-1.3.0.jar;其中有些包是需要单独下,下载地址就不再提供变量名:CLASSPATH 在该变量末尾加上%AXISCLASSPATH% (4).解压缩到D盘(根据自己需要),将里面文件夹下的axis拷贝到tomcat/webapp下,然后启动tomcat,访问http://localhost:8080/axis如果能够出来.说明axis已经发布成功(5). 进入到你的wsdl文件目录,然后执行:java org.apache.axis.wsdl.WSDL2Java -o server -d Session -s -S true xxx.wsdl ,会在当前目录下生成server文件夹,里面包含了你所需要的java类及delploy.wsdd和undelploy.wsdd.(服务端)(6).将这些生成的包拷贝到你工程目录的src下,然后编译。将classes下的文件全部拷贝到axis的classes文件夹下。(7),启动tomcat,(一定要起来),然后进入到delopy.wsdd所在的目录,执行java org.apache.axis.client.AdminClient deploy.wsdd.然后会在Tomcat 5.5\webapps\axis\WEB-INF下会发现多了个server-config.wsdd文件(8) 通过http://localhost:8080/axis/下的List可以看到服务了。 wsimport (netbean default)或者自己写ant xfire WsgenXfire/xfire2 (eclipse default) wsdl2java -gui xx.wsdl生成stub 我的博客里有篇写这个的文章。写好ant,执行完以后,就能得到class了。不过我那个ant你得改下才能用。 怎么把oracle数据库里Bolb类型的数据放到实体类里,然后展示到JSP页面上呢? 数据采集 java.util.zip压缩包 解压问题 EJB部署 在哪可以初始化参数? 100分求基于XML+JS的树形菜单!!!!!!!!!!!!!下午18:00分接贴! 菜鸟一名,想知道域名是怎样解析的? 有关EJB Object和Home Object的一点疑问(详细) 客户端调用Ejb问题 在APPLICATION里使用EJB,有点问题,各位能否帮忙,谢了。 标题:tomcat下部署web服务,session的问题。急,求思路!! hibernate update的问题 test
<wsdl:definitions targetNamespace="urn:listing4"
xmlns:tns="urn:listing4"
xmlns:listing5="urn:listing5"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:import namespace="urn:listing5" location="listing5.wsdl"/>
<wsdl:types>
<xsd:schema targetNamespace="urn:listing4"
xmlns:listing5="urn:listing5"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.w3.org/2001/XMLSchema"/>
<xsd:complexType name="Address">
<xsd:sequence>
<xsd:element name="streetNum" type="xsd:int"/>
<xsd:element name="streetName" type="xsd:string"/>
<xsd:element name="city" type="xsd:string"/>
<xsd:element name="state" type="xsd:string"/>
<xsd:element name="phone"
type="listing5:Phone" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="GetAddressRequest">
<wsdl:part name="name" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="GetAddressResponse">
<wsdl:part name="address" type="tns:Address"/>
</wsdl:message>
<wsdl:message name="GetPhoneRequest">
<wsdl:part name="name" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="GetPhoneResponse">
<wsdl:part name="phone"
type="listing5:Phone"
/>
</wsdl:message>
<wsdl:portType name="AddressBook">
<wsdl:operation name="getAddress">
<wsdl:input message="tns:GetAddressRequest"/>
<wsdl:output message="tns:GetAddressResponse"/>
</wsdl:operation>
<wsdl:operation name="getPhone">
<wsdl:input message="tns:GetPhoneRequest"/>
<wsdl:output message="tns:GetPhoneResponse"/>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>
清单 5. Phone 模式的 WSDL 文件
<?xml version="1.0" ?> <wsdl:definitions targetNamespace="urn:listing5"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xsd:schema targetNamespace="urn:listing5"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.w3.org/2001/XMLSchema"/>
<xsd:complexType name="Phone">
<xsd:sequence>
<xsd:element name="areaCode" type="xsd:int"/>
<xsd:element name="exchange" type="xsd:int"/>
<xsd:element name="number" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
</wsdl:definitions>
1. Java1.6+Tomcat5.5+MyEclipse+Axis1.4Java环境就不用多说
(1).从www.apache.org上下载axis ,我下载的是axis-bin-1_4
(2). 解压缩到D盘(根据自己需要)
(3).环境变量:
变量名:AXIS_HOME 值:D:\axis-1_4
变量名:AXIS_LIB 值:%AXIS_HOME%\WEB-INF\lib
变量名:AXISCLASSPATH值:%AXIS_LIB%\axis.jar;%AXIS_LIB%\axis-ant.jar;%AXIS_LIB%\axis-schema.jar;%AXIS_LIB%\commons-discovery-0.2.jar;%AXIS_LIB%\commons-logging-1.0.4.jar;%AXIS_LIB%\jaxrpc.jar;%AXIS_LIB%\log4j-1.2.8.jar;%AXIS_LIB%\saaj.jar;%AXIS_LIB%\wsdl4j-1.5.1.jar; %AXIS_LIB%\activation.jar;%AXIS_LIB%\mail.jar;%AXIS_LIB%\xmlsec-1.3.0.jar;
其中有些包是需要单独下,下载地址就不再提供
变量名:CLASSPATH 在该变量末尾加上%AXISCLASSPATH% (4).解压缩到D盘(根据自己需要),将里面文件夹下的axis拷贝到tomcat/webapp下,然后启动tomcat,访问http://localhost:8080/axis如果能够出来.说明axis已经发布成功
(5). 进入到你的wsdl文件目录,然后执行:java org.apache.axis.wsdl.WSDL2Java -o server -d Session -s -S true xxx.wsdl ,会在当前目录下生成server文件夹,里面包含了你所需要的java类及delploy.wsdd和undelploy.wsdd.(服务端)
(6).将这些生成的包拷贝到你工程目录的src下,然后编译。将classes下的文件全部拷贝到axis的classes文件夹下。
(7),启动tomcat,(一定要起来),然后进入到delopy.wsdd所在的目录,执行java org.apache.axis.client.AdminClient deploy.wsdd.
然后会在Tomcat 5.5\webapps\axis\WEB-INF下会发现多了个
server-config.wsdd文件
(8) 通过http://localhost:8080/axis/下的List可以看到服务了。
写好ant,执行完以后,就能得到class了。
不过我那个ant你得改下才能用。