首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

axis2集成到自个儿的项目中demo

2012-08-27 
axis2集成到自己的项目中demoserviceGroup?service nameNBIService? descriptionThis is the ser

axis2集成到自己的项目中demo
<serviceGroup>
?<service name="NBIService">
? <description>This is the service for revoking certificate.</description>
? <parameter name="ServiceClass" locked="false">oma.nbi.NBIServer</parameter>
? <operation name="sayHello">
?? <messageReceiver />
?? <actionMapping>urn:sayHelloRequest</actionMapping>
? </operation>
?</service>
</serviceGroup>

这是一种RawXMLINOutMessageReceiver模式的,适用于axiom绑定的架构,我们不用它,用RPC方式:

<?xml version="1.0" encoding="UTF-8"?>
<serviceGroup>
?<service name="AddService">
? <description>This is the service for revoking certificate.</description>
? <parameter name="ServiceClass" locked="false">axis2test.AddService</parameter>
? <operation name="add">
?? <messageReceiver />??
? </operation>
?</service>
</serviceGroup>

好了,server端就部署好了,现在启动tomcat,用ie查看wsdl,顺利的话,应该可以看到

http://localhost:8080/你web项目的名字/services/AddService?wsdl 来查看

第六步:

下面写客户端代码:

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;


public class TestClient {

??? public static void main(String[] args) throws AxisFault {
??????? EndpointReference targetEPR = new EndpointReference(
??????????????? "http://localhost/ext2/services/AddService.AddServiceHttpSoap11Endpoint/");
??????? RPCServiceClient serviceClient = new RPCServiceClient();
??????? Options options = serviceClient.getOptions();
??????? options.setTo(targetEPR);
??????? String ns = "http://axis2test";//这里axis2test应该是你的package路径,否则会报错找不到
??????? QName opAdd = new QName(ns, "add");
??????? Class[] returnTypes = new Class[]{Integer.class};
??????? Object[] opAddArgs = new Object[]{"199", "6"};
??????? Object[] response = serviceClient.invokeBlocking(opAdd,opAddArgs, returnTypes);
??????? Integer result = (Integer) response[0];
??????? if (result == null) {
??????????? System.out.println("hello didn't initialize!");
??????????? return;
??????? }
??????? System.out.println(result);
???????
??? }
}

http://localhost:8080/你web项目名字/services/AddService/add?a=5&b=17

,结果得到:

<ns:return>22</ns:return>

热点排行