| |
众所周知,微软公司正在全力打造.net,并准备将它作为向其他公司进攻的砝码,来保证其在业界的技术领先地位。 其实,微软公司在许多领域都处于领导地位,一些优秀的产品让其他公司难望其项颈,如操作系统 ,办公软件等基于windows平台的一些优秀的应用软件(如:ie)。但在美国,许多大公司非常反感微软一手包办的作风,也对微软的不放心,对其产品的安全性的担忧,所以大部分都用unix 和linux等非windows平台,许多服务器也是用的非windows平台,或是用自己开发的操作系统。但windows的方便性和界面友好性及众多的工具也是其他平台难以比拟的(应该没什么争议的),而unix和linux平台似乎只适合一些专家。能不能找到一个桥梁将windows产品同其他平台联系起来呢?目前有www.stryon.com公司正在实现这一点,开发了inet,将microsoft.net转换成java代码来实现跨平台。 例如用visual studio.net开发了一个web service程序: testclient.asmx: <%@ webservice language="c#" class="testclient" %> using system; using system.web.services; using system.web.services.protocols; using system.web.services.description; using system.xml; using system.xml.schema; using system.xml.serialization; using system.data; public class testclient : webservice { [webmethod()] public int testint(int a,int b){ return a+b; } [webmethod()] public struct1 teststruct(struct1 a){ return a; } [webmethod()] public int[] testintarr(int[] a){ return a; } [webmethod()] public struct1[] teststrarr(struct1[] a){ return a; } [webmethod()] public struct1 teststructandarr(struct1 a,struct1[] b){ return a; } [webmethod()] public struct1[][] teststrmanyarr(struct1[][] a){ return a; } } public class struct1:parent{ public int i=1; public string j="ok"; public struct2 s2; } public class parent{ public string p; } public class struct2{ public string sfield; } 我们可以用il2java 工具转换成java代码(il2java工具可以在www.stryon.com 网站上下载,包括在inet产品中),如:il2java http://localhost/testclient/testclient.asmx c:/temp,运行这个命令,将在c盘temp目录下产生 testclient.java 和testclient_info.java: testclient.java: import system.*; import system.reflection.*; import system.web.services.*; public class testclient extends webservice{ public int testint(int a, int b){ return a+b; } public struct1 teststruct(struct1 a){ return a; } public int[] testintarr(int[] a){ return a; } public struct1[] teststrarr(struct1[] a){ return a; } public struct1 teststructandarr(struct1 a, struct1[] b){ return a; } public struct1[][] teststrmanyarr(struct1[][] a){ return a; } public testclient(){ super(); } } 用来指明web service中有哪些web方法,以便被客户调用; testclient_info.java: import system.*; import system.reflection.*; import system.web.services.*; public class testclient_info implements imetadata{ public void filltype(type t){ long value = typeattributes.ansiclass.value__ | typeattributes.autolayout.value__ | typeattributes.beforefieldinit.value__ | typeattributes.class.value__ | typeattributes.public.value__; typeattributes attributes = new typeattributes(value); t.set_attributes(attributes); } public fieldinfo[] getfieldsimpl(type t){ return new fieldinfo[0]; } public constructorinfo[] getconstructorsimpl(type t){ long value = 0; constructorinfo ctor = null; parameterinfo param = null; methodattributes attributes = null; parameterattributes paramattrs = null; java.util.vector ctorvec = new java.util.vector(); // public testclient(); value = methodattributes.hidebysig.value__ | methodattributes.public.value__ | methodattributes.reuseslot.value__ | methodattributes.rtspecialname.value__ | methodattributes.specialname.value__; attributes = new methodattributes(value); ctor = new constructorinfo(t); ctorvec.addelement(ctor); ctor.set_attributes(attributes); ctor.set_name("testclient"); ctor.set_bindingflags(bindingflags.public.value__ | bindingflags.instance.value__); object[] objs = ctorvec.toarray(); ctorvec = null; constructorinfo[] ctors = new constructorinfo[objs.length]; java.lang.system.arraycopy(objs, 0, ctors, 0, objs.length); return ctors; } public methodinfo[] getmethodsimpl(type t){ long value = 0; methodinfo method = null; parameterinfo param = null; methodattributes attributes = null; parameterattributes paramattrs = null; java.util.vector mdvec = new java.util.vector(); // public int testint(int a, int b); value = methodattributes.hidebysig.value__ | methodattributes.public.value__ | methodattributes.reuseslot.value__; attributes = new methodattributes(value); method = new methodinfo(t); mdvec.addelement(method); method.set_attributes(attributes); method.set_name("testint"); method.set_returntype("system.int32"); method.set_bindingflags(bindingflags.public.value__ | bindingflags.instance.value__); value = 0; paramattrs = new parameterattributes(value); param = new parameterinfo(method); param.set_attributes(paramattrs); param.set_name("a"); param.set_paramtype("system.int32"); method.addparameterinfo(param); value = 0; paramattrs = new parameterattributes(value); param = new parameterinfo(method); param.set_attributes(paramattrs); param.set_name("b"); param.set_paramtype("system.int32"); method.addparameterinfo(param); // public struct1 teststruct(struct1 a); value = methodattributes.hidebysig.value__ | methodattributes.public.value__ | methodattributes.reuseslot.value__; attributes = new methodattributes(value); method = new methodinfo(t); mdvec.addelement(method); method.set_attributes(attributes); method.set_name("teststruct"); method.set_returntype("struct1"); method.set_bindingflags(bindingflags.public.value__ | bindingflags.instance.value__); value = 0;
|
|