您的位置:首页 > 编程语言

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());

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: