axis2客户端调用问题

saaaer saaaer 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我写了个 web service 用来发送短信,代码如下

package com.link.ws;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.tempuri.WS;
import org.tempuri.WSSoap;
/*
* author suncl
* 短信测试类
* date:2014/12/11
*/
public class SnsServer {
private static Log log = LogFactory.getLog(SnsServer.class);
private String corpID = "TEST0xxxx";
private String pwd = "xxxx";
public String PostSns(String mobiles,String content){

// String content = "xxxxxxxxx";
String cell = "";
String sendTime = "";
WS ws = new WS();

WSSoap soap;

soap = (WSSoap) ws.getWSSoap();
//发送短信
String res = soap.batchSend(this.corpID, this.pwd, mobiles, content, cell,
sendTime);
long resLong = Long.parseLong(res);
if (resLong > 0) {
log.info("发送成功,流水号为:" + resLong+",手机号为:"+mobiles+"内容为:"+content);
} else if (resLong == -1) {
log.info("账号未注册" );
} else if (resLong == -2) {
log.info("其他错误");
} else if (resLong == -3) {
log.info("帐号或密码错误");
} else if (resLong == -4) {
log.info("一次提交信息不能超过10000个手机号码,号码逗号隔开" );
} else if (resLong == -5) {
log.info("余额不足,请先充值" );
} else {
log.info("未知错误,错误号为:" + resLong);
}
return res;
}
public static void main(String[] args) {
String mobiles="15531032581";
String content = "xxx";
SnsServer t=new SnsServer();
t.PostSns(mobiles, content);

// 返回短信余额
// String snsBal = soap.selSum(CorpID, Pwd);
// log.info("短信余额为:" + snsBal);

}
}



service.xml

<service name="Sns">
<Description>
Sns poster
</Description>
<parameter name="ServiceClass" locked="false">com.link.ws.SnsServer</parameter>
<operation name="PostSns">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
</service>

因为PostSns有参数,这个xml文件是否需要给这个方法加参数?
客户端调用 webservice

package com.link.client;

import java.net.MalformedURLException;
import java.rmi.RemoteException;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

/*
* 短信客户端
* author:suncl
* date:2014/12/12
*/
public class Client {
public static void main(String[] args) throws RemoteException,
ServiceException, MalformedURLException {
String mobiles = "15531032581";
String content = "xxxxxxxxxxxxxx";

String method = "PostSns";
try{
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(
"http://localhost:8080/axis2/services/Sns"));
call.setOperationName(new QName("http://ws.link.com", method));
call.setUseSOAPAction(true);
call.addParameter(new QName("http://ws.link.com", "mobiles"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new QName("http://ws.link.com", "content"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setSOAPActionURI("http://ws.link.com/GetServerList");
String k = (String) call.invoke(new Object[] { mobiles, content }); // 因为返回值是String类型,所以这里调用的返回值也是String类型
System.out.println(">>> " + k); // 返回值输出
}catch(Exception ex){
ex.printStackTrace();
}

}
}



...全文
评论 1
收藏 已收藏
分享
返回顶部
saaaer
Web 开发 81,108 成员 341,721 内容