网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>JAVA>>新手入门>>基础入门>查看文档  
  microsoft.net的java实现     
  文章作者:未知  文章来源:水木森林  
  查看:80次  录入:管理员--2007-11-17  
 
  众所周知,微软公司正在全力打造.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;
 
 
上一篇: 使用simpson规则完成积分运算    下一篇: java.util包简介如何开发应用之一
  相关文档
java套接字编程(上)(2) 11-17
常见的十四种java开发工具及其特点 11-16
高手编程之——jtextarea操作 11-17
java技巧: 推动jbuttongroup 11-17
java socket编程(三) 11-17
apache geronimo 1.0 m3 released 11-17
[java100例]033、读写文件(字节) 11-17
java趣味“java网络机器人” 11-17
swing入门基础知识点全接触 11-17
java中鲜为人知的缺点(上) 11-17
enterprise javabeans查询语言(1) 11-17
web 服务代理组件创建 jsf web 服务客户端(5) 11-17
j2eeweb-tomcat5.5.9中文问题解决方案 11-17
用java获得ip地址 11-17
论jsp数据库连接池的必要性 11-17
运行headless java服务器 11-16
java 程序中的多线程 11-16
java下数字类型的转换 11-17
技术分析:使用eclipse进行swt编程(图) 11-17
选择java接口还是抽象类 11-17
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
技术电话:13616026886
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息