package com.mgj.xfiretext.domain; import java.io.Serializable; /** private Long userId; private String accountId; private String userName; private Date lastLogin; public String getAccountId() { public void setAccountId(String accountId) { public Date getLastLogin() { public void setLastLogin(Date lastLogin) { public Long getUserId() { public void setUserId(Long userId) { public String getUserName() { public void setUserName(String userName) {
import com.mgj.xfiretext.domain.User; package com.mgj.xfiretext.webserver; import java.util.Date; import org.apache.commons.logging.Log; import com.mgj.xfiretext.domain.User; /** |
<?xml version="1.0"?> <project name="xfire" default="genfiles" basedir="."> <property name="lib" value="${basedir}/../WebRoot/WEB-INF/lib" /> <path id="myclasspath"> <fileset dir="${lib}"> <include name="*.jar" /> </fileset> <pathelement location="${genfiles}" /> </path> <!--${basedir}/../src表示放在src下面 --> <!--${basedir}/../../ssh/src表示放在另外一個工程(ssh)下的src下面 --> <!--${basedir}表示當前目錄--> <!--通過XFire ant任務生成客戶端代碼的存放位置--> <property name="code_path" value="${basedir}/../src" /> <!--需要生成客戶端代碼的wsdl文件--> <property name="wsdl_path" value="http://localhost:8090/xfire/services/UserService?wsdl" /> <!--生成客戶端代碼的包名--> <property name="code_package" value="com.mgj.xfiretext.webserver.client" /> <!-- Remove classes directory for clean build --> <target name="clean" description="Prepare for clean build"> <delete dir="${code_path}"/> <mkdir dir="${code_path}"/> </target> <!--<target name="genfiles" depends="clean" description="Generate the files"> --> <target name="genfiles" description="Generate the files"> <taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask" classpathref="myclasspath" /> <!--outputDirectory屬性定義創建的代碼所在的文件夾 wsdl是web服務的wsdl文件 package代表創建的代碼的package --> <wsgen outputDirectory="${code_path}" wsdl="${wsdl_path}" package="${code_package}" binding="xmlbeans" /> </target> </project> |
<?xml version="1.0" encoding="UTF-8"?> <bean id="userService" <bean name="UserService" |
package test; import java.net.MalformedURLException; package test; import java.net.MalformedURLException; import org.apache.xmlbeans.XmlObject; import com.zx.xfiretext.domain.User; /** UserServiceClient userServiceClient = new UserServiceClient();
|
接下來,我們按照一下步驟來。
(1)啟動TOMCAT
(2)我們應當執行build.xml文件,因為是在ECLIPSE中開發,所以只要點擊【右鍵】之后,找到【ANT BUILD】選項,然后點擊。就會生成UserServiceClient.java、UserServiceImpl、UserServicePortType這個三個類。
(3)執行測試類。
我們就會看到結果:
userId=123, userName=mgj, lastLogin=Sat Nov 01 17:27:50 CST 2008 <out xmlns="http://webserver.xfiretext.zx.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <accountId xmlns="http://domain.xfiretext.zx.com">testAccount</accountId> <lastLogin xmlns="http://domain.xfiretext.zx.com">2008-11-01T17:27:51.343+08:00</lastLogin> <userId xmlns="http://domain.xfiretext.zx.com">123</userId> <userName xmlns="http://domain.xfiretext.zx.com">mgj</userName> </out> accountId: testAccount userId:123 |
說明:以上我也是根據網上前輩做的例子,在結合自己的一些實踐做出來的。