WebService核心文件【web-config.wsdd】調用操作
阿新 • • 發佈:2017-08-09
app names row data- esp scope ice tac namespace
WebService核心文件【server-config.wsdd】詳解及調用示例
作者:瑪莎拉蒂-小賤人
一、準備工作
導入需要的jar包:
二、配置web.xml
在web工程的web.xml中添加如下配置:
[html] view plain copy
- <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>
三、配置server-config.wsdd文件
在WEB-INF下添加WebService核心文件server-config.wsdd:
[html] view plain copy
- <?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="attachments.Directory"
- value="D:\myproject\calileo\xxx\WebContent\WEB-INF\attachments" />
- <parameter name="dotNetSoapEncFix" value="true" />
- <parameter name="enableNamespacePrefixOptimization" value="true" />
- <parameter name="sendXMLDeclaration" value="true" />
- <parameter name="attachments.implementation"
- value="org.apache.axis.attachments.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>
四、測試WSDL
在瀏覽器輸入:http://localhost:8080/xxx/services/SjrkkService?wsdl //xxx和server-config.wsdd文件中的xxx一致,訪問結果如下:
五、調WebService
[java] view plain copy
- /**
- * 調用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;
- }
WebService核心文件【web-config.wsdd】調用操作