日期:2014-05-16 浏览次数:20839 次
package yibudiaoyong;
public class YiBuDiaoYongService {
public String getName(){
try {
System.out.println("getName方法正在执行");
// 延迟5秒
Thread.sleep(2000);
} catch (Exception e) {
}
return "火星";
}
}
<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();
}
}