WebService核心文件【server-config.wsdd】详解及调用示例
作者:Vashon
一、准备工作
导入需要的jar包:
二、配置web.xml
在web工程的web.xml中添加如下配置:
AxisServlet
org.apache.axis.transport.http.AxisServlet
15
AxisServlet
/services/*
三、配置server-config.wsdd文件
在WEB-INF下添加WebService核心文件server-config.wsdd:
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
value="D:\myproject\calileo\xxx\WebContent\WEB-INF\attachments" />
value="org.apache.axis.attachments.AttachmentsImpl" />
type="java:org.apache.axis.transport.local.LocalResponder" />
type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" />
value="org.apache.axis.transport.http.QSListHandler" />
value="org.apache.axis.transport.http.QSWSDLHandler" />
value="org.apache.axis.transport.http.QSListHandler" />
value="org.apache.axis.transport.http.QSMethodHandler" />
value="org.apache.axis.transport.http.QSMethodHandler" />
value="org.apache.axis.transport.http.QSWSDLHandler" />
四、测试WSDL
五、调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