天天看點

比.Net Micro Framework還小的.net Framework

這是飛天的最新一款智能卡産品,前短時間抽時間研究了一下,整體感覺還不錯,實作了clr中有關檔案操作(有些函數好像有些問題)、加密算法等指令。

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

由于我們這邊的項目組開發的就是MF3.0的檔案系統,是以對它們這個這麼小的東東有CPU、有作業系統,支援clr,并且支援檔案系統很感興趣。

它的檔案系統是FAT16(MF實作的是FAT32,這就要求存儲空間至少有32.52M),通過PC上的一個程式可以實作上下傳檔案。此外該系統最大的特點就是可以執行.net程式。

下面是簡單的程式,一個是運作在智能卡上(server),一個運作在普通PC上。

//服務端程式,需要用上面的工具(load file)把編譯好的程式上傳到智能卡上,然後在設定運作即可。

using System;

using System.Runtime.Remoting;

using System.Runtime.Remoting.Channels;

using SmartCard.Runtime.Remoting.Channels.APDU;

namespace MyCompany.MyOnCardApp

{

    ///< Abstract >

    /// MyServer Abstract .

    ///</ Abstract >

    public class MyServer

    {

        ///< Abstract >

        ///URI of remote object to be exposed

        ///</ Abstract >

        private const string REMOTE_OBJECT_URI = "MyService.uri";

        ///Register Card Service

        ///</ Abstract >

        ///<returns></returns>

        public static int Main()

        {

            //Register communication channel for server to start listening

            ChannelServices.RegisterChannel(new APDUServerChannel());

            //Register application as a service

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyService), REMOTE_OBJECT_URI, WellKnownObjectMode.Singleton);

            return 0;

        }

   }

}

//用戶端程式,在PC機上運作,可以遠端執行服務端上的函數有點DCOM的感覺。

using System.Text;

using MyCompany.MyOnCardApp;

// Make sure the stub of the server application bas been added as reference or its interface has been declared

// stub file is automatically generated in [Server Project Output]/Stub when compiling server application

namespace MyCompany.MyClientApp

    public class MyClient

        private const string URL = "apdu://selfdiscover/MyService.uri";

        public static void Main()

            // Create and register a communication channel

            APDUClientChannel channel = new APDUClientChannel();

            ChannelServices.RegisterChannel(channel);

            // Get reference to remote object

            MyService service = (MyService)Activator.GetObject(typeof(MyService), URL);

            // Call remote method

            service.FileOperation();

            // Unregister communication channel

            ChannelServices.UnregisterChannel(channel);

                           channel.Dispose();

    }

繼續閱讀