posts - 32,comments - 8,trackbacks - 0
          比較難的一部分

          前提條件:
          axis安裝路徑 C:\ericsson\javaextend\axis-1_4
          項(xiàng)目名稱(chēng):axisdemo
          已經(jīng)有的類(lèi):com.service.myService.java
          配置文件:server-config.wsdd

          1. 在項(xiàng)目添加java2wsdl目錄

          2.目錄下面添加build.xml文件
          <?xml version="1.0" encoding="UTF-8"?>
          <project name="Generate WSDL from JavaBeans as Web Services" default="j2w-all" basedir=".">
              
          <property name="build.dir" value="../build/classes" />
              
          <property name="axis.dir" location="C:\ericsson\javaextend\axis-1_4" />
              
          <path id="classpath.id">
                  
          <fileset dir="${axis.dir}/lib">
                      
          <include name="*.jar" />
                  
          </fileset>
                  
          <pathelement location="${build.dir}" />
              
          </path>
              
          <taskdef name="axis-java2wsdl" classname="org.apache.axis.tools.ant.wsdl.Java2WsdlAntTask" loaderref="axis">
                  
          <classpath refid="classpath.id" />
              
          </taskdef>
              
          <target name="j2w-all">
                  
          <antcall target="j2w-JavaBeanWS" />
              
          </target>
              
          <target name="j2w-JavaBeanWS">
                  
          <axis-java2wsdl classname="com.service.myService" classpath="${build.dir}" methods="getusername" output="myService.wsdl" location="http://localhost:8080/axisdemo/services/myService" namespace="http://localhost:8080/axisdemo/services/myService" namespaceImpl="http://localhost:8080/axisdemo/services/myService">
                  
          </axis-java2wsdl>
              
          </target>
          </project>
          注意:build.dir / axis.dir / j2w-javabeanws幾個(gè)地方的內(nèi)容要修改。

          3. 右鍵點(diǎn)擊build.xml,運(yùn)行ant,就可以看到生成了myService.wsdl

          4.現(xiàn)在要把這個(gè)wsdl轉(zhuǎn)化成為java,新建目錄:wsdl2java

          5. 新建一個(gè)build.xml,內(nèi)容:
          <?xml version="1.0" encoding="UTF-8"?>
          <project name="wsclient" default="all" basedir=".">
              
          <property name="axis.home" location="C:\ericsson\javaextend\axis-1_4" />
              
          <property name="options.output" location="../wsdl2java" />
              
          <path id="axis.classpath">
                  
          <fileset dir="${axis.home}/lib">
                      
          <include name="**/*.jar" />
                  
          </fileset>
              
          </path>
              
          <taskdef resource="axis-tasks.properties" classpathref="axis.classpath" />
              
          <target name="-WSDL2Axis" depends="init">
                  
          <mkdir dir="${options.output}" />
                  
          <axis-wsdl2java output="${options.output}" url="${options.WSDL-URI}" verbose="true" />
              
          </target>
              
          <target name="init">
                  
          <echo>Warning: please update the associated WSDL file(s) in the folder wsdl before running the target!</echo>
                  
          <echo>Warning: Just run the target(s) related with your developing work!</echo>
                  
          <echo>
                  
          </echo>
              
          </target>
              
          <target name="all">
                  
          <antcall target="myService" />
              
          </target>
              
          <target name="myService">
                  
          <antcall target="-WSDL2Axis">
                      
          <param name="options.WSDL-URI" location="../java2wsdl/myService.wsdl" />
                  
          </antcall>
              
          </target>
          </project>
          注意修改的地方:axis.home

          6.build ant,在wsdl2java目錄下面多出來(lái)了4個(gè)類(lèi):
          myService.java
          MyServiceService.java
          myServiceServiceLocator.java
          MyServiceSoapBindingStub.java
          全部拷貝到src目錄下面

          7.在src目錄下面添加類(lèi):
          package com.axistest;

          import localhost.axisdemo.services.myService.MyService;
          import localhost.axisdemo.services.myService.MyServiceServiceLocator;

          public class myServiceTestorByStubs
          {
              
          public static void main(String[] args) throws Exception
              {
                  MyServiceServiceLocator Service 
          = new MyServiceServiceLocator();
                  MyService port 
          = Service.getmyService();
                  String response 
            port.getusername(鄒萍");
                  System.out.println(response);
              }
          }

          8.最后運(yùn)行java application就完成了


          posted on 2008-12-18 11:03 張辰 閱讀(385) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Dr. Oops
          主站蜘蛛池模板: 汝城县| 萝北县| 高雄县| 禄丰县| 黑山县| 句容市| 汕头市| 江门市| 澄迈县| 上犹县| 临沭县| 保德县| 彩票| 大新县| 遂溪县| 呼伦贝尔市| 汉寿县| 徐汇区| 汉中市| 正镶白旗| 宝鸡市| 化德县| 开江县| 普兰县| 邯郸县| 闽清县| 合阳县| 大埔区| 高密市| 蕲春县| 随州市| 巨野县| 庆元县| 余江县| 鄄城县| 桦南县| 景德镇市| 上饶市| 海安县| 西丰县| 朝阳区|