XFire使用WSDL生成客户端代码
2008-08-08 15:18
393 查看
WSDL 如下:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://xfire.codehaus.org/BookService" xmlns:tns="http://xfire.codehaus.org/BookService" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://demo.xfire.codehaus.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://xfire.codehaus.org/BookService">
<xsd:element name="getBooks">
<xsd:complexType/>
</xsd:element>
<xsd:element name="getBooksResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="book" nillable="true" type="ns1:Book">
<xsd:annotation>
<xsd:documentation>All books.</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://demo.xfire.codehaus.org">
<xsd:complexType name="Book">
<xsd:sequence>
<xsd:element minOccurs="0" name="author" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="isbn" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="title" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getBooksRequest">
<wsdl:part name="parameters" element="tns:getBooks">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getBooksResponse">
<wsdl:part name="parameters" element="tns:getBooksResponse">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="BookServicePortType">
<wsdl:documentation/>
<wsdl:operation name="getBooks">
<wsdl:documentation/>
<wsdl:input name="getBooksRequest" message="tns:getBooksRequest">
</wsdl:input>
<wsdl:output name="getBooksResponse" message="tns:getBooksResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BookServiceHttpBinding" type="tns:BookServicePortType">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getBooks">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getBooksRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getBooksResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="BookService">
<wsdl:port name="BookServiceHttpPort" binding="tns:BookServiceHttpBinding">
<wsdlsoap:address location="http://hehui:8080/xfire/services/BookService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
build.xml 如下:
<?xml version="1.0"?>
<project name="wsgen" default="wsgen" basedir=".">
<taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask"
/>
<target name="wsgen" description="remove all built files">
<wsgen outputDirectory="."
wsdl="BookService.wsdl" package="net" overwrite="true"/>
</target>
</project>
运行ant 即可生成客户端代码。
使用生成的代码访问webservice:
import net.BookServiceClient;
import org.codehaus.xfire.demo.Book;
public class XFireClient2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BookServiceClient client = new BookServiceClient();
Book book = client.getBookServiceHttpPort().getBooks();
System.out.println(book.getTitle().getValue());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://xfire.codehaus.org/BookService" xmlns:tns="http://xfire.codehaus.org/BookService" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://demo.xfire.codehaus.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://xfire.codehaus.org/BookService">
<xsd:element name="getBooks">
<xsd:complexType/>
</xsd:element>
<xsd:element name="getBooksResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="book" nillable="true" type="ns1:Book">
<xsd:annotation>
<xsd:documentation>All books.</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://demo.xfire.codehaus.org">
<xsd:complexType name="Book">
<xsd:sequence>
<xsd:element minOccurs="0" name="author" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="isbn" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="title" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getBooksRequest">
<wsdl:part name="parameters" element="tns:getBooks">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getBooksResponse">
<wsdl:part name="parameters" element="tns:getBooksResponse">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="BookServicePortType">
<wsdl:documentation/>
<wsdl:operation name="getBooks">
<wsdl:documentation/>
<wsdl:input name="getBooksRequest" message="tns:getBooksRequest">
</wsdl:input>
<wsdl:output name="getBooksResponse" message="tns:getBooksResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BookServiceHttpBinding" type="tns:BookServicePortType">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getBooks">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getBooksRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getBooksResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="BookService">
<wsdl:port name="BookServiceHttpPort" binding="tns:BookServiceHttpBinding">
<wsdlsoap:address location="http://hehui:8080/xfire/services/BookService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
build.xml 如下:
<?xml version="1.0"?>
<project name="wsgen" default="wsgen" basedir=".">
<taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask"
/>
<target name="wsgen" description="remove all built files">
<wsgen outputDirectory="."
wsdl="BookService.wsdl" package="net" overwrite="true"/>
</target>
</project>
运行ant 即可生成客户端代码。
使用生成的代码访问webservice:
import net.BookServiceClient;
import org.codehaus.xfire.demo.Book;
public class XFireClient2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BookServiceClient client = new BookServiceClient();
Book book = client.getBookServiceHttpPort().getBooks();
System.out.println(book.getTitle().getValue());
}
}
相关文章推荐
- webService---使用Xfire从WSDL生成客户端(详)
- 使用java的wsimport.exe工具生成wsdl的客户端代码
- 使用CXF将wsdl文件生成客户端代码命令
- 使用axis2解析wsdl生成Webservice客户端代码
- 使用axis2,根据WSDL生成java客户端代码
- 根据wsdl文件使用xfire生成webservice客户端
- 使用Myeclipse插件将wsdl生成java客户端代码
- 使用cmd根据WSDL网址生成java客户端代码
- 使用cmd根据WSDL网址生成java客户端代码
- 在 Jboss中如何使用 WSDL 来生成客户端代码 JAVA
- 使用wsdl2java根据wsdl生成java客户端代码
- 使用Axis2中的工具wsdl2Java的生成客户端和服务端代码
- 使用java的wsimport.exe工具生成wsdl的客户端代码
- 使用axis2解析wsdl生成Webservice客户端代码
- 使用cmd webservice wsdl网址生成客户端代码
- java wsdl反向生成源码,并使用CXF实现客户端调用代码
- 使用java的wsimport.exe工具生成wsdl的客户端代码
- 使用axis2,根据WSDL生成java客户端代码
- java wsdl反向生成源码,并使用CXF实现客户端调用代码
- 使用axis2,根据WSDL生成java客户端代码