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

2021-06-07 13:01

阅读:574

标签:发布   response   bar   detail   技术分享   准备工作   namespace   deploy   simple   

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

 

 

 

作者:玛莎拉蒂-小贱人

 

一、准备工作

 

导入需要的jar包:

 

 

                                                                               技术分享

 

 

 

二、配置web.xml

 

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

 

[html] view plain copy
 
技术分享技术分享
  1. servlet
  2.         servlet-name>AxisServletservlet-name
  3.         servlet-class>org.apache.axis.transport.http.AxisServletservlet-class
  4.         load-on-startup>15load-on-startup
  5.     servlet>    
  6.     servlet-mapping
  7.         servlet-name>AxisServletservlet-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.      
  34.     service name="SjrkkService" provider="java:RPC"
  35.          
  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】调用操作

标签:发布   response   bar   detail   技术分享   准备工作   namespace   deploy   simple   

原文地址:http://www.cnblogs.com/liujian-java/p/7326936.html


评论


亲,登录后才可以留言!