1、需要导入的jar包
2、配置web.xml文件
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
<load-on-startup>15</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
3、配置server-config.wsdd文件
server-config.wsdd放在固定目录在WEB-INF下,添加WebService核心文件server-config.wsdd:
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<globalConfiguration>
<!-- 变量设定 -->
<parameter name="sendMultiRefs" value="true" />
<parameter name="disablePrettyXML" value="true" />
<parameter name="adminPassword" value="admin" />
<parameter name="p_w_uploads.Directory"
value="D:\myproject\calileo\xxx\WebContent\WEB-INF\p_w_uploads" />
<parameter name="dotNetSoapEncFix" value="true" />
<parameter name="enableNamespacePrefixOptimization" value="true" />
<parameter name="sendXMLDeclaration" value="true" />
<parameter name="p_w_uploads.implementation"
value="org.apache.axis.p_w_uploads.AttachmentsImpl" />
<parameter name="sendXsiTypes" value="true" />
<requestFlow>
<handler type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="session" />
</handler>
<handler type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="request" />
<parameter name="extension" value=".jwr" />
</handler>
</requestFlow>
</globalConfiguration>
<handler name="LocalResponder"
type="java:org.apache.axis.transport.local.LocalResponder" />
<handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper" />
<handler name="Authenticate"
type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" />
<!-- 核心重点:服务发布,name:表示发布的service名 --> <service name="SjrkkService" provider="java:RPC"> <!-- 发布的service接口类 --> <parameter name="className" value="com.xxx.ws.SjrkkService" /> </service>
<transport name="http">
<requestFlow>
<handler type="URLMapper" />
<handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
</requestFlow>
<parameter name="qs:list"
value="org.apache.axis.transport.http.QSListHandler" />
<parameter name="qs:wsdl"
value="org.apache.axis.transport.http.QSWSDLHandler" />
<parameter name="qs.list"
value="org.apache.axis.transport.http.QSListHandler" />
<parameter name="qs.method"
value="org.apache.axis.transport.http.QSMethodHandler" />
<parameter name="qs:method"
value="org.apache.axis.transport.http.QSMethodHandler" />
<parameter name="qs.wsdl"
value="org.apache.axis.transport.http.QSWSDLHandler" />
</transport>
<transport name="local">
<responseFlow>
<handler type="LocalResponder" />
</responseFlow>
</transport>
</deployment>
4、测试wsdl
在浏览器输入:http://localhost:8080/xxx/services/SjrkkService?wsdl //xxx和server-config.wsdd文件中的xxx一致,访问结果如下:
五、调WebService
/**
* 调用webservice的方法.
* @param url wsdl链接
* @param method 调用的接口
* @param idCard 传入的参数
* @return
* @throws Exception
*/
private String getWebServiceResult( String url, String method, String idCard) throws Exception{
String rtnXml = null;
try {
String endpoint = url;
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(method);
rtnXml = (String) call.invoke(new Object[]{idCard});
} catch (Exception e) {
e.printStackTrace();
}
return rtnXml;
}
// 以前项目调用, 转载地址: http://www.cnblogs.com/ywx-vashon/p/5452893.html