首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

axis2创办webservice客户端全过程(调用.net web服务)

2012-10-16 
axis2创建webservice客户端全过程(调用.net web服务)运行环境:??? myeclipse + tomcat6 + .Net web servic

axis2创建webservice客户端全过程(调用.net web服务)

运行环境:

??? myeclipse + tomcat6 + .Net web service

1.下载axis2-1.5-bin.zip

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

2.下载

?调用命令
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;    }    }
?

热点排行