1,导入jar包
2,在web.xml注册service
<servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>Apache-Axis Servlet</display-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<!--<init-param>-->
<!--<param-name>axis2.xml.path</param-name>-->
<!--<param-value>/WEB-INF/conf/axis2.xml</param-value>-->
<!--<param-name>axis2.xml.url</param-name>-->
<!--<param-value>http://localhost/myrepo/axis2.xml</param-value>-->
<!--<param-name>axis2.repository.path</param-name>-->
<!--<param-value>/WEB-INF</param-value>-->
<!--<param-name>axis2.repository.url</param-name>-->
<!--<param-value>http://localhost/myrepo</param-value>-->
<!--</init-param>-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>AxisAdminServlet</servlet-name>
<display-name>Apache-Axis AxisAdmin Servlet (Web Admin)</display-name>
<servlet-class>
org.apache.axis2.webapp.AxisAdminServlet</servlet-class>
</servlet>
<servlet>
<display-name>Axis Admin Servlet</display-name>
<servlet-name>AdminServlet</servlet-name>
<servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<!-- servlet>
<servlet-name>SOAPMonitorService</servlet-name>
<display-name>SOAPMonitorService</display-name>
<servlet-class>org.apache.axis2.soapmonitor.servlet.SOAPMonitorService</servlet-class>
<init-param>
<param-name>SOAPMonitorPort</param-name>
<param-value>5001</param-value>
</init-param>
<init-param>
<param-name>SOAPMonitorHostName</param-name>
<param-value>localhost</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet -->
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisAdminServlet</servlet-name>
<url-pattern>/axis2-admin/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AdminServlet</servlet-name>
<url-pattern>/servlet/AdminServlet</url-pattern>
</servlet-mapping>
里面有些service不是必须的,但也有用,可以在调试的时候查看
webservie信息。
3,拷贝modules到WEB-INF下
4,在WEB-INF下建立services文件夹(或者直接拷贝axis2中jar包自带的)
5,拷贝axis2.xml到WEB-INF下
6,开始写类和方法,例如:
package org.hd.axis2.device;
import org.hd.business.service.BusinessService;
import org.hd.business.summary.model.CallSummaryVo;
import org.rd.framework.common.container.ContainerManager;
public class AddBillSuccessCallBack{
private BusinessService businessService = (BusinessService)ContainerManager.getComponent(BusinessService.BEAN_ID);
public String hadAddBillForTheCall(String callid,String billNumber){
String resultMessage="";
CallSummaryVo call=new CallSummaryVo();
if(callid==null||callid.trim().equals("")){
resultMessage="未获取到通话callid,操作失败!";
}else if(billNumber==null||billNumber.trim().equals("")){
resultMessage="未获取到工单号billNumber,操作失败!";
}else{
call.setVoiceid(callid);
call.setBill_number(billNumber);
businessService.updateSummaryByWebservice(call);
resultMessage="收到信息:callid="+callid+",billNumber="+billNumber;
}
System.out.println("调用webservice的结果信息:"+resultMessage);
return resultMessage;
}
}
7,按照package org.hd.axis2.device的结构压缩成arr格式的文件,
需要编译后的class文件。
结构如下:
afterAddBillMessage
|
----------------------------
META-INF | org
----------------------------
services.xml | hd
----------------------------
|axis2
----------------------------
|device
----------------------------
|AddBillSuccessCallBack.class
8,编写services.xml内容,在上面的META-INF下:
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<service name="afterAddBillMessage">
<description>
This service is to give message to the calling for add a bill
</description>
<parameter name="ServiceClass">org.hd.axis2.device.AddBillSuccessCallBack</parameter>
<operation name="hadAddBillForTheCall">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
</service>
9,最后获得afterAddBillMessage.aar(名字随便起)
10,afterAddBillMessage.aar放到WEB-INF/services下
ok,webservice写好了,可以访问了。
可以在浏览器地址栏输入请求url查看xml信息,不过那是为了查看或者调试用的。
webservice存在的意义是为了程序调用,所以要访问,必须洗客户端代码。
这里指给出一个测试类:
AddBillSuccessCallBackClient.java
package org.hd.axis2.client;
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 AddBillSuccessCallBackClient {
public static void main(String args[]) throws AxisFault {
// 使用RPC方式调用WebService
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
// 指定调用WebService的URL
EndpointReference targetEPR = new EndpointReference(
"http://10.23.130.118:8095/HelpDesk/services/afterAddBillMessage");
options.setTo(targetEPR);
// 指定hadAddBillForTheCall方法的参数值
Object[] opAddEntryArgs = new Object[] { "FF5B82690A1808170148E7DF2E5890BC","billnumberIUERREO9834-SDF" };
// 指定sayHelloToPerson方法返回值的数据类型的Class对象
Class[] classes = new Class[] { String.class };
// 指定要调用的sayHelloToPerson方法及WSDL文件的命名空间
// QName opAddEntry = new QName("http://ws.apache.org/axis2",
// "sayHelloMethod");
// QName opAddEntry = new QName("http://service", "sayHelloMethod");
QName opAddEntry = new QName("http://device.axis2.hd.org",
"hadAddBillForTheCall");
// 调用sayHelloToPerson方法并输出该方法的返回值
System.out.println(serviceClient.invokeBlocking(opAddEntry,
opAddEntryArgs, classes)[0]);
}
}
有了测试类,更方便调试。