客户端就不需要怎么配置了
只需要把xfire的包导入工程 然后新建一个文件 (这里本来有三种方法 但是只实现了两种 后续看能否补上否)如下:
package com.dlmu.database.client;
import java.net.MalformedURLException;
import java.net.URL;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import com.dlmu.database.xfire.service.IXFireService;
import org.codehaus.xfire.client.Client;
public class xfireClient {
/**
* @param args
* @author Administrator
*/
public static void main(String[] args) {
/** 创建客户端实例 */
xfireClient xfireTest = new xfireClient();
/** 根据服务地址创建客户端调用程序 */
xfireTest.testClientByServerAddress();
/** 动态客户端的实现 */
xfireTest.testClientByDynamic();
/**动态客户端的实现 整合spring*/
xfireTest.testClientByDynamic_Spring();
}
/**
* 根据服务地址创建客户端调用程序
*
* @author Administrator
*/
public void testClientByServerAddress() {
Service srvcModel = new ObjectServiceFactory()
.create(IXFireService.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
String helloWorldURL = "http://localhost:8080/xfire/services/SayHelloService";
try {
IXFireService srvc = (IXFireService) factory.create(srvcModel,
helloWorldURL);
srvc.sayHello("Administrator");
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
/**
* 根据WSDL自动生成客户端代码
*
* @author Administrator
*/
public void testClientByCode() {
}
/**
* 动态客户端的实现
*
* @author Administrator
*/
public void testClientByDynamic() {
String wsURL = "http://localhost:8080/xfire/services/SayHelloService?wsdl";
try {
System.out.println(" ----> 初始客户端 <---- ");
Client client = new Client(new URL(wsURL));
Object[] results = client.invoke("sayHello",
new Object[] { "Michael" });
System.out.println("results的长度:" + results.length);
System.out.println(results[0]);
System.out.println(" ----> 客户端调用结束 <---- ");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 动态客户端的实现
*
* @author Administrator
*/
public void testClientByDynamic_Spring() {
System.out.println(" ----> Spring start<---- ");
String wsURL = "http://localhost:8021/XFireWebService/services/IConditionInfoService?wsdl";
try {
System.out.println(" ----> 初始客户端 <---- ");
Client client = new Client(new URL(wsURL));
Object[] results = client.invoke("sayHello",
new Object[] { "Michael" });
System.out.println("results的长度:" + results.length);
System.out.println(results[0]);
System.out.println(" ----> 客户端调用结束 <---- ");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(" ----> Spring end<---- ");
}
}
哦了