WEB开发网      婵犵數濞€濞佳囧磹婵犳艾鐤炬い鎰堕檮閸嬬喐銇勯弽銊с€掗梻鍕閺岋箑螣娓氼垱笑闂佽姘﹂褔婀佸┑鐘诧工妤犲憡绂嶉崜褏纾奸弶鍫涘妼缁楁岸鏌熷畡鐗堝殗闁诡喒鏅犲畷褰掝敃閵堝棙顔忔繝鐢靛仦閸ㄥ爼骞愰幘顔肩;闁规崘绉ぐ鎺撳亹闁绘垶锕╁Λ鍕⒑閹肩偛濡奸悗娑掓櫇缁顓兼径妯绘櫇闂佹寧绻傞弻濠囨晝閸屾稓鍘甸柣搴㈢⊕閿氶柣蹇ョ稻缁绘繃绻濋崘銊т紝闂佽鍨伴崯鏉戠暦閻旂⒈鏁傞柛鈾€鏅欑槐妯衡攽閻愬樊鍤熷┑顔藉劤铻為柛鏇ㄥ墯閸欏繘鏌嶉崫鍕櫣缂佲偓婢跺绠鹃柟瀛樼箘閿涘秵顨ラ悙顏勭伈闁诡喖缍婂畷鎯邦槻婵℃彃顭烽弻娑㈠Ω閵夈儺鍔夌紓浣稿€哥粔褰掑极閹剧粯鏅搁柨鐕傛嫹 ---闂傚倷鐒︾€笛兠洪埡鍛闁跨噦鎷�
开发学院WEB开发Jsp Microsoft.Net的Java实现 阅读

Microsoft.Net的Java实现

 2008-01-05 08:38:55 来源:WEB开发网 闂傚倷绶氬ḿ褍螞閹绢喖绠柨鐕傛嫹闂傚倷绀侀幉锟犲垂閻㈠灚宕查柟鎵閸庡秵銇勯幒鎴濃偓鐢稿磻閹炬枼妲堟繛鍡楃С濞岊亞绱撻崒姘扁枌闁瑰嚖鎷�婵犵數濮幏鍐川椤撴繄鎹曢梻渚€娼уú銈吤洪妸鈺佺劦妞ゆ帊鑳堕埊鏇㈡煏閸モ晛浠х紒杈╁仱閺佹捇鏁撻敓锟�闂傚倷绶氬ḿ褍螞閹绢喖绠柨鐕傛嫹  闂傚倷鑳舵灙缂佺粯顨呴埢宥夊即閵忕姵鐎梺缁樺姇閻忔氨鈧凹鍓熷娲垂椤曞懎鍓伴梺閫炲苯澧紒澶婄秺瀵濡歌閸嬫捇妫冨☉娆忔殘闂佷紮缍€娴滎剟鍩€椤掑倹鏆柛瀣躬瀹曚即寮借閺嗭箓鏌ㄩ悤鍌涘
核心提示:众所周知,微软公司正在全力打造.Net,并预备将它作为向其他公司进攻的砝码,Microsoft.Net的Java实现,来保证其在业界的技术领先地位, 其实,包括在iNet产品中),如:il2java http://localhost/testClient/testClient.asmx c:\temp,运行这个命令,微

  众所周知,微软公司正在全力打造.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;

Tags:Microsoft Net Java

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接