WebService axis2异步调用无返回值,该怎么处理
1个回答
2016-10-25 · 知道合伙人软件行家
关注
展开全部
service代码:
Java code?
package yibudiaoyong;
public class YiBuDiaoYongService {
public String getName(){
try {
System.out.println("getName方法正在执行");
// 延迟5秒
Thread.sleep(2000);
} catch (Exception e) {
}
return "火星";
}
}
service.xml配置文件代码:
<service name="yibudiaoyongService">
<description> 异步调用演示 </description>
<parameter name="ServiceClass">
yibudiaoyong.YiBuDiaoYongService
</parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</messageReceivers>
</service>
异步调用程序:
package yibudiaoyong;
import javax.xml.namespace.QName;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.async.AxisCallback;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class RPCAsyncClient {
public static void main(String[] args) throws Exception {
RPCServiceClient serviceClient =new RPCServiceClient();
Options options=serviceClient.getOptions();
EndpointReference targetERP=new EndpointReference("http://localhost:8080/axis2/services/yibudiaoyongService");
options.setTo(targetERP);
Object[] opAddEntryArgs=new Object[]{};
QName opAddEntry=new QName("http://yibudiaoyong","getName");
serviceClient.invokeNonBlocking(opAddEntry, opAddEntryArgs, new AxisCallback(){
public void onComplete() {
// TODO Auto-generated method stub
}
public void onError(Exception arg0) {
// TODO Auto-generated method stub
}
public void onFault(MessageContext arg0) {
// TODO Auto-generated method stub
}
public void onMessage(MessageContext mc) {
System.out.println("111111111111111111");
System.out.println(mc.getEnvelope().getFirstElement().getFirstElement().getFirstElement().getText());
}
});
System.out.println("异步调用!");
// 阻止程序退出
Class[] classes = new Class[] {String.class};
//System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0]);
System.in.read();
}
}
Java code?
package yibudiaoyong;
public class YiBuDiaoYongService {
public String getName(){
try {
System.out.println("getName方法正在执行");
// 延迟5秒
Thread.sleep(2000);
} catch (Exception e) {
}
return "火星";
}
}
service.xml配置文件代码:
<service name="yibudiaoyongService">
<description> 异步调用演示 </description>
<parameter name="ServiceClass">
yibudiaoyong.YiBuDiaoYongService
</parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</messageReceivers>
</service>
异步调用程序:
package yibudiaoyong;
import javax.xml.namespace.QName;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.async.AxisCallback;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class RPCAsyncClient {
public static void main(String[] args) throws Exception {
RPCServiceClient serviceClient =new RPCServiceClient();
Options options=serviceClient.getOptions();
EndpointReference targetERP=new EndpointReference("http://localhost:8080/axis2/services/yibudiaoyongService");
options.setTo(targetERP);
Object[] opAddEntryArgs=new Object[]{};
QName opAddEntry=new QName("http://yibudiaoyong","getName");
serviceClient.invokeNonBlocking(opAddEntry, opAddEntryArgs, new AxisCallback(){
public void onComplete() {
// TODO Auto-generated method stub
}
public void onError(Exception arg0) {
// TODO Auto-generated method stub
}
public void onFault(MessageContext arg0) {
// TODO Auto-generated method stub
}
public void onMessage(MessageContext mc) {
System.out.println("111111111111111111");
System.out.println(mc.getEnvelope().getFirstElement().getFirstElement().getFirstElement().getText());
}
});
System.out.println("异步调用!");
// 阻止程序退出
Class[] classes = new Class[] {String.class};
//System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0]);
System.in.read();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询