playframework2.0 通过xfire调用webservice

本文介绍如何使用PlayFramework 2.2.3通过XFire调用外部WebService接口。具体包括所需依赖包、接口定义及调用示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境:

playframework 2.2.3

webservice:

webservice的地址:http://122.144.134.134:8080/toyota/services/MsgWebService?wsdl 

webservice含有的方法:public String getReportData(String data);  public String getMoData(String data);


需求:在playframework2.2.3中调用外部的webservice接口

方案:利用xfire来实现改需求

步骤:1.引入需要的包:

commons-codec-1.3.jar
commons-httpclient-3.0.jar
jdom-1.0.jar
wsdl4j-1.6.1.jar
xfire-all-1.2.6.jar

2.根据webservice 中的方法定义接口

package webservice;

public interface IMsgWebService {
	public String getReportData(String data);
	
	public String getMoData(String data);
}

3.调用

import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

public static void main(String[] args) {
		String serviceUrl = "http://122.144.134.134:8080/toyota/services/MsgWebService";
		Service serviceModel = new ObjectServiceFactory().create(
				IMsgWebService.class, null, serviceUrl + "?wsdl", null);
		XFireProxyFactory serviceFactory = new XFireProxyFactory();
		try {
			IMsgWebService service = (IMsgWebService) serviceFactory.create(
					serviceModel, serviceUrl);
			String data = "13082314#test1#13570902010#402881933f182d42013f182ddddd0601#测试回复短#001&13082315#test1#13570902011#402881933f182d42013f182ddddd0602#测试回复短信内容#002&13082316#test1#13570902012#402881933f182d42013f182ddddd0603#测试回复短信内容二#003&13082317#test1#13570902013#402881933f182d42013f182ddddd0604#测试回复短信内容三#004";
			String returnData = service.getMoData(data);
			System.out.println(returnData);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值