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

          前提條件:
          axis安裝路徑 C:\ericsson\javaextend\axis-1_4
          項目名稱:axisdemo
          已經有的類:com.service.myService.java
          配置文件:server-config.wsdd

          1. 在項目添加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幾個地方的內容要修改。

          3. 右鍵點擊build.xml,運行ant,就可以看到生成了myService.wsdl

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

          5. 新建一個build.xml,內容:
          <?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目錄下面多出來了4個類:
          myService.java
          MyServiceService.java
          myServiceServiceLocator.java
          MyServiceSoapBindingStub.java
          全部拷貝到src目錄下面

          7.在src目錄下面添加類:
          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.最后運行java application就完成了


          posted on 2008-12-18 11:03 張辰 閱讀(391) 評論(0)  編輯  收藏 所屬分類: Dr. Oops
          主站蜘蛛池模板: 河北省| 塔河县| 枣庄市| 林芝县| 亚东县| 黄梅县| 扎赉特旗| 阿拉尔市| 定陶县| 岳普湖县| 呼和浩特市| 彭阳县| 肇州县| 霍邱县| 南安市| 铅山县| 绥棱县| 深州市| 东海县| 莎车县| 新源县| 乡城县| 甘南县| 新竹县| 民权县| 东明县| 文化| 永平县| 石门县| 兰州市| 思南县| 鄢陵县| 景洪市| 二连浩特市| 高青县| 芦溪县| 花垣县| 浠水县| 北流市| 湘阴县| 紫云|