微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xfire(客户端实现)

客户端就不需要怎么配置了

只需要把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<---- ");
}
}


哦了

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐