且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

比.Net Micro Framework还小的.net Framework

更新时间:2022-09-25 22:50:21

这是飞天的最新一款智能卡产品,前短时间抽时间研究了一下,整体感觉还不错,实现了clr中有关文件操作(有些函数好像有些问题)、加密算法等指令。

 

比.Net Micro Framework还小的.net Framework 比.Net Micro Framework还小的.net Framework


 

 

 


 

由于我们这边的项目组开发的就是MF3.0的文件系统,所以对它们这个这么小的东东有CPU、有操作系统,支持clr,并且支持文件系统很感兴趣。

它的文件系统是FAT16(MF实现的是FAT32,这就要求存储空间至少有32.52M),通过PC上的一个程序可以实现上下传文件。此外该系统最大的特点就是可以执行.net程序。

比.Net Micro Framework还小的.net Framework


 

 

 

下面是简单的程序,一个是运行在智能卡上(server),一个运行在普通PC上。


  1. //服务端程序,需要用上面的工具(load file)把编译好的程序上传到智能卡上,然后在设置运行即可。  
  2.  
  3. using System;  
  4.  
  5. using System.Runtime.Remoting;  
  6.  
  7. using System.Runtime.Remoting.Channels;  
  8.  
  9. using SmartCard.Runtime.Remoting.Channels.APDU;  
  10.  
  11. namespace MyCompany.MyOnCardApp  
  12.  
  13. {  
  14.  
  15.     ///< Abstract >  
  16.  
  17.     /// MyServer Abstract .  
  18.  
  19.     ///</ Abstract >  
  20.  
  21.     public class MyServer  
  22.  
  23.     {  
  24.  
  25.         ///< Abstract >  
  26.  
  27.         ///URI of remote object to be exposed  
  28.  
  29.         ///</ Abstract >  
  30.  
  31.         private const string REMOTE_OBJECT_URI = "MyService.uri";  
  32.  
  33.         ///< Abstract >  
  34.  
  35.         ///Register Card Service  
  36.  
  37.         ///</ Abstract >  
  38.  
  39.         ///<returns></returns>  
  40.  
  41.         public static int Main()  
  42.  
  43.         {  
  44.  
  45.             //Register communication channel for server to start listening  
  46.  
  47.             ChannelServices.RegisterChannel(new APDUServerChannel());  
  48.  
  49.             //Register application as a service  
  50.  
  51.             RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyService), REMOTE_OBJECT_URI, WellKnownObjectMode.Singleton);  
  52.  
  53.             return 0;  
  54.  
  55.         }  
  56.  
  57.    }  
  58.  
  59. }  
  60.  
  61.    
  62.  
  63. //客户端程序,在PC机上运行,可以远程执行服务端上的函数有点DCOM的感觉。  
  64.  
  65. using System;  
  66.  
  67. using System.Runtime.Remoting;  
  68.  
  69. using System.Runtime.Remoting.Channels;  
  70.  
  71. using SmartCard.Runtime.Remoting.Channels.APDU;  
  72.  
  73. using System.Text;  
  74.  
  75. using MyCompany.MyOnCardApp;  
  76.  
  77.    
  78.  
  79. // Make sure the stub of the server application bas been added as reference or its interface has been declared  
  80.  
  81. // stub file is automatically generated in [Server Project Output]\Stub when compiling server application  
  82.  
  83. namespace MyCompany.MyClientApp  
  84.  
  85. {  
  86.  
  87.     public class MyClient  
  88.  
  89.     {  
  90.  
  91.         private const string URL = "apdu://selfdiscover/MyService.uri";  
  92.  
  93.         public static void Main()  
  94.  
  95.         {  
  96.  
  97.             // Create and register a communication channel  
  98.  
  99.             APDUClientChannel channel = new APDUClientChannel();  
  100.  
  101.             ChannelServices.RegisterChannel(channel);  
  102.  
  103.             // Get reference to remote object  
  104.  
  105.             MyService service = (MyService)Activator.GetObject(typeof(MyService), URL);  
  106.  
  107.             // Call remote method  
  108.  
  109.             service.FileOperation();  
  110.  
  111.             // Unregister communication channel  
  112.  
  113.             ChannelServices.UnregisterChannel(channel);  
  114.  
  115.                            channel.Dispose();  
  116.  
  117.         }  
  118.  
  119.     }  
  120.  
  121. }  
  122.  
  123.  
  124.  

 







本文转自yefanqiu51CTO博客,原文链接:http://blog.51cto.com/yfsoft/324061,如需转载请自行联系原作者