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.现在要把这个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 张辰 阅读(376) 评论(0)  编辑  收藏 所属分类: Dr. Oops

只有注册用户登录后才能发表评论。


网站导航: