webservice-之使用axis+spring开发2

三、配置文件 (全部放在 /WEB-INF/ 目录下

1、 web.xml web 加载 spring axis 配置

<!--Spring 框架需要引入的配置文件及相关类 -->

       <context-param>

              <param-name>contextConfigLocation</param-name>

              <param-value>/WEB-INF/applicationContext.xml</param-value>

       </context-param>

       <servlet>

              <servlet-name>context</servlet-name>

              <servlet-class>

                     org.springframework.web.context.ContextLoaderServlet

              </servlet-class>

              <load-on-startup>1</load-on-startup>

       </servlet>

       <!--axis 需要引入的 Servlet -->

       <servlet>

              <servlet-name>axis</servlet-name>

              <servlet-class>

                     org.apache.axis.transport.http.AxisServlet

              </servlet-class>

              <load-on-startup>2</load-on-startup>

       </servlet>

       <servlet-mapping>

              <servlet-name>axis</servlet-name>

              <url-pattern>/services/*</url-pattern>

       </servlet-mapping>

       <!--axis Web Service Web 发布路径 -->

2、 applicationContext.xml spring 的配置

<?xml version="1.0" encoding="UTF-8"?>  

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"

"http://www.springframework.org/dtd/spring-beans.dtd">    

<beans>

<bean id="myHelloWorldBean" class="test.HelloWorldBean">

              <property name="helloStr">

                     <value>Say Hello to :</value>

              </property>

       </bean>

</beans>

3、 server-config.wsdd axis 服务配置

<deployment xmlns="http://xml.apache.org/axis/wsdd/"

       xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

       <handler name="URLMapper"

              type="java:org.apache.axis.handlers.http.URLMapper" />   

       <!-- 系统服务 -->

       <service name="AdminService" provider="java:MSG">

              <parameter name="allowedMethods" value="AdminService" />

              <parameter name="enableRemoteAdmin" value="false" />

              <parameter name="className" value="org.apache.axis.utils.Admin" />

              <namespace>http://xml.apache.org/axis/wsdd/</namespace>

       </service>

       <service name="Version" provider="java:RPC">

              <parameter name="allowedMethods" value="getVersion" />

              <parameter name="className" value="org.apache.axis.Version" />

       </service>     

       <!-- 自定义服务 -->

       <service name="myWebService" provider="java:RPC">

              <parameter name="className"

                     value="test.HelloWorldWebService" />

              <parameter name="allowedMethods" value="*" />

       </service>

       <transport name="http">

              <requestFlow>

                     <handler type="URLMapper" />

              </requestFlow>

       </transport>

</deployment>

四、测试 客户端 TestWebServiceClient.java

package test;

import javax.xml.namespace.QName;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

public class TestWebServiceClient

{    

       public static void main(String[] args)

       {    

              try

              {

                     String wsdlUrl

= "http://localhost:8080/spring-axis/services/myWebService?wsdl";

                     String nameSpaceUri

= "http://localhost:8080/spring-axis/services/myWebService";

                     // 创建调用对象

                     Service service = new Service();

                     Call call = null;

                     call = (Call) service.createCall();

                     // 调用 getMessage

                     System.out.println(">>>getMessage");

                     call.setOperationName(new QName(nameSpaceUri, "getMessage"));

                     call.setTargetEndpointAddress(new java.net.URL(wsdlUrl));

                     String ret = (String) call.invoke(new Object[] { "ABC" });

                     System.out.println("return value is " + ret);

              }

              catch (Exception e)

           &nbs ...

posted @ 2008-11-04 17:42  Earl_86  阅读(801)  评论(0编辑  收藏  举报