日期:2014-05-20 浏览次数:20776 次
public class SimpleService
{
public String getGreeting(String name)
{
System.out.println("-----"+name+"------");
return "您好,"+name;
}
public int getPrice()
{
return new java.util.Random().nextInt(1000);
}
}
- <ns:getGreetingResponse xmlns:ns="http://ws.apache.org/axis2">
<return>您好,null</return>
</ns:getGreetingResponse>
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import com.sun.tools.jxc.gen.config.Classes;
public class RPCClinnt {
public static void main(String[] args) throws Exception {
//使用RPC方式调用WebService
RPCServiceClient serviceClient=new RPCServiceClient();
Options options=serviceClient.getOptions();
//指定调用WebService的URL
EndpointReference targetERP=new EndpointReference("http://localhost:8080/axis2/services/SimpleService");
options.setTo(targetERP);
//指定getGreeting方法的参数值
Object[] opAddEntryArgs=new Object[]{"超人"};
//指定getGreeting方法返回值的数据类型的Class对象
Class[] classes=new Class[] {String.class};
//指定要调用的getGreeting方法及WSDL文件的命名空间
QName opAddEntry=new QName("http://ws.apache.org/axis2", "getGreeting");
//调用getGreeting方法并输出该方法的返回值
System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs,classes)[0]);
}
}