加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

xfire(客户端实现)

发布时间:2020-12-17 00:28:35 所属栏目:安全 来源:网络整理
导读:客户端就不需要怎么配置了 只需要把xfire的包导入工程 然后新建一个文件 (这里本来有三种方法 但是只实现了两种 后续看能否补上否)如下: package com.dlmu.database.client; import java.net.MalformedURLException; import java.net.URL; import org.cod

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

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


哦了

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读