1. 程式人生 > >WebService核心文件【web-config.wsdd】調用操作

WebService核心文件【web-config.wsdd】調用操作

app names row data- esp scope ice tac namespace

WebService核心文件【server-config.wsdd】詳解及調用示例

作者:瑪莎拉蒂-小賤人

一、準備工作

導入需要的jar包:

技術分享

二、配置web.xml

在web工程的web.xml中添加如下配置:

[html] view plain copy 技術分享技術分享
  1. <servlet>
  2. <servlet-name>AxisServlet</servlet-name>
  3. <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
  4. <load-on-startup>15</load-on-startup>
  5. </servlet>
  6. <servlet-mapping>
  7. <servlet-name>AxisServlet</servlet-name>
  8. <url-pattern>/services/*</url-pattern>
  9. </servlet-mapping>

三、配置server-config.wsdd文件

在WEB-INF下添加WebService核心文件server-config.wsdd:

[html] view plain copy 技術分享技術分享
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <deployment xmlns="http://xml.apache.org/axis/wsdd/"
  3. xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
  4. <globalConfiguration>
  5. <!-- 變量設定 -->
  6. <parameter name="sendMultiRefs" value="true" />
  7. <parameter name="disablePrettyXML" value="true" />
  8. <parameter name="adminPassword" value="admin" />
  9. <parameter name="attachments.Directory"
  10. value="D:\myproject\calileo\xxx\WebContent\WEB-INF\attachments" />
  11. <parameter name="dotNetSoapEncFix" value="true" />
  12. <parameter name="enableNamespacePrefixOptimization" value="true" />
  13. <parameter name="sendXMLDeclaration" value="true" />
  14. <parameter name="attachments.implementation"
  15. value="org.apache.axis.attachments.AttachmentsImpl" />
  16. <parameter name="sendXsiTypes" value="true" />
  17. <requestFlow>
  18. <handler type="java:org.apache.axis.handlers.JWSHandler">
  19. <parameter name="scope" value="session" />
  20. </handler>
  21. <handler type="java:org.apache.axis.handlers.JWSHandler">
  22. <parameter name="scope" value="request" />
  23. <parameter name="extension" value=".jwr" />
  24. </handler>
  25. </requestFlow>
  26. </globalConfiguration>
  27. <handler name="LocalResponder"
  28. type="java:org.apache.axis.transport.local.LocalResponder" />
  29. <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper" />
  30. <handler name="Authenticate"
  31. type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" />
  32. <!-- 核心重點:服務發布,name:表示發布的service名 -->
  33. <service name="SjrkkService" provider="java:RPC">
  34. <!-- 發布的service接口類 -->
  35. <parameter name="className" value="com.xxx.ws.SjrkkService" />
  36. </service>
  37. <transport name="http">
  38. <requestFlow>
  39. <handler type="URLMapper" />
  40. <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
  41. </requestFlow>
  42. <parameter name="qs:list"
  43. value="org.apache.axis.transport.http.QSListHandler" />
  44. <parameter name="qs:wsdl"
  45. value="org.apache.axis.transport.http.QSWSDLHandler" />
  46. <parameter name="qs.list"
  47. value="org.apache.axis.transport.http.QSListHandler" />
  48. <parameter name="qs.method"
  49. value="org.apache.axis.transport.http.QSMethodHandler" />
  50. <parameter name="qs:method"
  51. value="org.apache.axis.transport.http.QSMethodHandler" />
  52. <parameter name="qs.wsdl"
  53. value="org.apache.axis.transport.http.QSWSDLHandler" />
  54. </transport>
  55. <transport name="local">
  56. <responseFlow>
  57. <handler type="LocalResponder" />
  58. </responseFlow>
  59. </transport>
  60. </deployment>

四、測試WSDL

在瀏覽器輸入:http://localhost:8080/xxx/services/SjrkkService?wsdl //xxx和server-config.wsdd文件中的xxx一致,訪問結果如下:

技術分享

五、調WebService

[java] view plain copy 技術分享技術分享
  1. /**
  2. * 調用webservice的方法.
  3. * @param url wsdl鏈接
  4. * @param method 調用的接口
  5. * @param idCard 傳入的參數
  6. * @return
  7. * @throws Exception
  8. */
  9. private String getWebServiceResult( String url, String method, String idCard) throws Exception{
  10. String rtnXml = null;
  11. try {
  12. String endpoint = url;
  13. Service service = new Service();
  14. Call call = (Call) service.createCall();
  15. call.setTargetEndpointAddress(new java.net.URL(endpoint));
  16. call.setOperationName(method);
  17. rtnXml = (String) call.invoke(new Object[]{idCard});
  18. } catch (Exception e) {
  19. e.printStackTrace();
  20. }
  21. return rtnXml;
  22. }

WebService核心文件【web-config.wsdd】調用操作