axis2-1.4.1 下的
axis2.war 放到tomcat下
简单编写一个服务,供给系统外部调用
-
import java.util.Random;
- ?
- ?
- ?
-
public class SimpleService {
- ?
-
public String getGreeting(String name) {
-
return "你好 "+name;
- }
- ?
-
public int getPrice() {
-
return new Random().nextInt(1000);
- }
- }
import java.util.Random;
public class SimpleService {
public String getGreeting(String name) {
return "你好 "+name;
}
public int getPrice() {
return new Random().nextInt(1000);
}
}
SimpleService.class 放到 WEB-INF/pojo 下
就这么简单 就构成了一个服务
客户端(Java):
?
-
package client;
- ?
-
import java.rmi.RemoteException;
-
import java.util.Iterator;
- ?
-
import javax.xml.namespace.QName;
- ?
-
import org.apache.axiom.om.OMAbstractFactory;
-
import org.apache.axiom.om.OMElement;
-
import org.apache.axiom.om.OMFactory;
-
import org.apache.axiom.om.OMNamespace;
-
import org.apache.axis2.AxisFault;
-
import org.apache.axis2.Constants;
-
import org.apache.axis2.addressing.EndpointReference;
-
import org.apache.axis2.client.Options;
-
import org.apache.axis2.client.ServiceClient;
-
import org.apache.axis2.rpc.client.RPCServiceClient;
- ?
-
public class RPCClient {
- ?
-
public static void main(String[] args) throws RemoteException {
- ?
- ?
- ?
- SimpleServiceStub stub = new SimpleServiceStub();
- SimpleServiceStub.GetGreeting gg = new SimpleServiceStub.GetGreeting();
- gg.setName("超人");
- System.out.println(stub.getGreeting(gg).get_return());
- System.out.println(stub.getPrice().get_return());
- }
- ?
-
public static void runRPC() throws AxisFault {
- RPCServiceClient serviceClient = new RPCServiceClient();
- Options options = serviceClient.getOptions();
- ?
- EndpointReference taretEPR = new EndpointReference(
-
"http://localhost:8080/axis2/services/SimpleService");
- options.setTo(taretEPR);
- ?
- Object[] opAddEntryArgs = new Object[]{"超人"};
- Class[] classes = new Class[]{String.class};
- QName opAddEntry = new QName("http://ws.apache.org/axis2","getGreeting");
- ?
- System.out.println(serviceClient.invokeBlocking(opAddEntry,opAddEntryArgs,classes)[0]);
- ?
- classes = new Class[]{int.class};
- opAddEntry = new QName("http://ws.apache.org/axis2","getPrice");
- System.out.println(serviceClient.invokeBlocking(opAddEntry,classes)[0]);
- } ??