axis2客户端调用问题
我写了个 web service 用来发送短信,代码如下
service.xml
因为PostSns有参数,这个xml文件是否需要给这个方法加参数?
客户端调用 webservice
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();
}
}
}
...全文
相关推荐
axis2客户端调用axis1服务接口
"这篇文章主要介绍了如何使用Axis2作为客户端来调用Axis1服务接口的详细步骤,特别是如何处理可能存在的库冲突问题,并提供了具体的RPC方式调用WebService的代码示例。"在Java
webservice五种发布方式及客户端调用.pdf
**客户端调用WebService**调用WebService通常涉及以下步骤:- 创建服务代理对象:使用JAX-WS的`Service`类或CXF、Axis2提供的工具生成服务客户端代码。
cxf客户端调用axis服务端流程
调试时,开启CXF的日志可以帮助定位问题。总之,使用CXF客户端调用Axis服务端涉及多个步骤,包括生成客户端代码、配置客户端、创建服务代理以及进行实际调用。
axis2客户端调用工程代码
本篇将详细介绍如何在Axis2环境下编写客户端代码来调用工程中的服务。1.
在自己的项目中利用axis2+spring发布webservice与客户端调用包括session
**客户端调用**:对于客户端,它们需要使用Axis2的客户端API或者基于JAX-WS的工具来调用这些Web服务。调用过程中,需要正确传递session信息,以保持会话的有效性。6.


Web 开发
