手写axis实现webservice通讯

目的:方便以后再需要实现webserice服务端,不需要安装插件让eclipse自动生成。省掉每次发布一个服务就要自动生成一堆看不懂得代码。

配置:
1、建立一个普通的web 工程
2、导入jar包
        通过验证必须要引入
                     axis.jar
                  commons-discovery-0.2.jar
                  commons-logging-1.0.4.jar
                  saaj.jar
                  wsdl4j-1.5.1.jar

3、在web-inf下新建文件server-config.wsdd (见附件)内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<deployment name="defaultClientConfig"
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
    xmlns:handler="http://xml.apache.org/axis/wsdd/providers/handler" xmlns="http://xml.apache.org/axis/wsdd/">
    <globalConfiguration name="GlobalConfiguration1" type="" regenerateElement="false">
        <requestFlow name="RequestFlow1" type="" regenerateElement="false">
            <handler name="Handler1"
                type="java:org.apache.axis.handlers.JWSHandler" regenerateElement="false">
                <parameter name="scope" value="session" regenerateElement="false"/>
            </handler>
            <handler name="Handler2"
                type="java:org.apache.axis.handlers.JWSHandler" regenerateElement="false">
                <parameter name="scope" value="request" regenerateElement="false"/>
                <parameter name="extension" value=".jwr" regenerateElement="false"/>
            </handler>
        </requestFlow>
    </globalConfiguration>
    <handler name="URLMapper"
        type="java:org.apache.axis.handlers.http.URLMapper" regenerateElement="false"/>
    <handler name="LocalResponder"
        type="java:org.apache.axis.transport.local.LocalResponder" regenerateElement="false"/>
    <handler name="Authenticate"
        type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" regenerateElement="false"/>
    <transport name="http" type="" regenerateElement="false">
        <requestFlow name="RequestFlow1" type="" regenerateElement="false">
            <handler name="Handler1" type="URLMapper" regenerateElement="false"/>
            <handler name="Handler2"
                type="java:org.apache.axis.handlers.http.HTTPAuthHandler" regenerateElement="false"/>
        </requestFlow>
    </transport>
    <transport name="local" type="" regenerateElement="false">
        <responseFlow name="ResponseFlow1" type="" regenerateElement="false">
            <handler name="Handler1" type="LocalResponder" regenerateElement="false"/>
        </responseFlow>
    </transport>
    <service name="AdminService" type="" regenerateElement="false" provider="java:MSG">
        <parameter name="allowedMethods" value="AdminService" regenerateElement="false"/>
        <parameter name="enableRemoteAdmin" value="false" regenerateElement="false"/>
        <parameter name="className" value="org.apache.axis.utils.Admin" regenerateElement="false"/>
        <namespace>http://xml.apache.org/axis/wsdd/</namespace>
    </service>
    <service name="Version" type="" regenerateElement="false" provider="java:RPC">
        <parameter name="allowedMethods" value="getVersion" regenerateElement="false"/>
        <parameter name="className" value="org.apache.axis.Version" regenerateElement="false"/>
    </service>
   
    <!-- 测试服务 -->
    <service name="test" provider="java:RPC">
    <parameter name="className" value="cn.test"/>
    </service>
   
</deployment>


每次添加服务只要添加
   <service name="test" provider="java:RPC">
    <parameter name="className" value="cn.test"/>
    </service>
即可发布。

4、修改web.xml文件,在文件中添加servlet 内容如下:
  
   <servlet>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>


5、 新建测试服务类 cn.test 里边随便写方法。就可以发布出去了。
6、 通过 ..../services  url 链接就可以查看了wsdl了

lib附件:含有上面提到的相应文件,对应相应的位置放入即可。
webservice-axis附件:是仅含有手写webservice例子的web工程

你可能感兴趣的:(apache,eclipse,Web,xml,webservice)