WebService核心文件web-config.wsdd调用操作

Posted 玛莎拉蒂-小贱人

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WebService核心文件web-config.wsdd调用操作相关的知识,希望对你有一定的参考价值。

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.  
  33.     <!-- 核心重点:服务发布,name:表示发布的service名 --> 
  34.     <service name="SjrkkService" provider="java:RPC"
  35.         <!-- 发布的service接口类 --> 
  36.         <parameter name="className" value="com.xxx.ws.SjrkkService" /> 
  37.     </service
  38.  
  39.     <transport name="http"
  40.         <requestFlow
  41.             <handler type="URLMapper" /> 
  42.             <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler" /> 
  43.         </requestFlow
  44.         <parameter name="qs:list" 
  45.             value="org.apache.axis.transport.http.QSListHandler" /> 
  46.         <parameter name="qs:wsdl" 
  47.             value="org.apache.axis.transport.http.QSWSDLHandler" /> 
  48.         <parameter name="qs.list" 
  49.             value="org.apache.axis.transport.http.QSListHandler" /> 
  50.         <parameter name="qs.method" 
  51.             value="org.apache.axis.transport.http.QSMethodHandler" /> 
  52.         <parameter name="qs:method" 
  53.             value="org.apache.axis.transport.http.QSMethodHandler" /> 
  54.         <parameter name="qs.wsdl" 
  55.             value="org.apache.axis.transport.http.QSWSDLHandler" /> 
  56.     </transport
  57.     <transport name="local"
  58.         <responseFlow
  59.             <handler type="LocalResponder" /> 
  60.         </responseFlow
  61.     </transport
  62. </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.          
  16.             call.setTargetEndpointAddress(new java.net.URL(endpoint)); 
  17.             call.setOperationName(method); 
  18.          
  19.             rtnXml = (String) call.invoke(new Object[]{idCard}); 
  20.              
  21.              
  22.         } catch (Exception e) { 
  23.             e.printStackTrace(); 
  24.         }  
  25.         return rtnXml; 
  26.     } 

以上是关于WebService核心文件web-config.wsdd调用操作的主要内容,如果未能解决你的问题,请参考以下文章

将 Webservice 数据缓存到核心数据中

WebService的简单运用添加删除

webservice和restful的区别

webservice框架cxf

Axis1.4底层加载server-config.wsdd文件的过程

webService和Restful