运行环境:

    myeclipse + tomcat6 + .Net web service

1.下载axis2-1.5-bin.zip

   url : http://ws.apache.org/axis2/download.cgi

2.下载Axis2 并解压到一个目标目录

3.设置AXIS2_HOME环境变量来指出目标目录

  例如:

       变量名:AXIS2_HOME

       变量值:D:\Program Files\axis2-1.5

4.JAVA_HOME环境变量也不要忘记指定向JDK路径

5.将axis2/lib目录下的jar包添加到自己的项目中。

6.通过Dos命令行生成stub类文件

   通过wsdl2java 可能查看用法
axis2创建webservice客户端全过程(调用.net web服务)

 调用命令
axis2创建webservice客户端全过程(调用.net web服务)
 生成如下文件:


axis2创建webservice客户端全过程(调用.net web服务)
 我们发现被生成的文件并不是在Dos当前目录下,是因为此路径还包括了.net WebService 文件的命名空间。

 

7. 将刚生成的两个文件拷贝至自已的项目下

 


axis2创建webservice客户端全过程(调用.net web服务)
 发现又有错误了,是因为文件里的包名与所在的包是不一致的,改一下包名即可。

这里很郁闷,为什么生成的文件里wsdl路径不保存成常量,而要一个一个地方的改,太不方便了(如果想放到配置文件里)

 

8.创建调用类StubUserClient

package client;

import java.rmi.RemoteException;
import client.UserServiceStub.ClassA;
import client.UserServiceStub.ClassB;
import client.UserServiceStub.GetDept;

public class StubuserClient
{
	/**
	 * @param args
	 * @throws RemoteException
	 */
	public static void main(String[] args) throws RemoteException
	{
		UserServiceStub stub = new UserServiceStub();
		
		// axis2在做http传输时采用了「chunked」模式,而.net的web server不支持
		// 「axis中使用的是HTTP/1.0协议,而.NET和axis2使用的是HTTP/1.1协议,后两者的区别在于
		// NET未使用ns1的命名空間前缀打包SOAP請求,且axis2使用了Content- Encoding: chunked头。
		// 所以必須在axis2中設置一下。」
		stub._getServiceClient().getOptions().setProperty(
				org.apache.axis2.transport.http.HTTPConstants.CHUNKED,
				Boolean.FALSE);
		
		UserServiceStub.ClassA a = new ClassA();
		a.setName("testAAA");
		a.setPwd("testPwd");
		a.setAge(55);
		UserServiceStub.GetDept getDept0 = new GetDept();
		getDept0.setA(a);
		ClassB b = stub.getDept(getDept0).getGetDeptResult();
		System.out.println("Name: " + b.getName() + "    Dept: " + b.getDept());
	}
}

 9. Run as 这个类,成功执行,ok!

 

附:.net web service 类代码

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://org.zhanglh/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class UserService : System.Web.Services.WebService
{
    public UserService () {

        //如果使用设计的组件,请取消注释以下行 
        //InitializeComponent(); 
    }

    [WebMethod]
    public ClassB GetDept(ClassA a) {
        ClassB b = new ClassB();
        
        if (String.IsNullOrEmpty(a.Name))
        {
            b.Name = "default";
            b.Dept = "default";
        }
        else
        {
            b.Name = a.Name;
            b.Dept = "市场部";
        }
        return b;
    }
    
}
 

相关文章:

  • 2021-08-15
  • 2021-12-03
  • 2021-10-17
  • 2021-10-23
  • 2021-09-12
  • 2021-05-15
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2021-11-27
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2022-01-16
相关资源
相似解决方案