私は .Net スマート カードを持っており、c# を使用してカード アプリケーションとホスト アプリケーションをビルドしています。実際、スマート カードは .Net リモート処理でサーバーとして機能します。
スマート カードには、リモート オブジェクト (Myclass) があり、リモート メソッドを呼び出します。
public int AddPerson (string name,string age)
このオブジェクトに情報を追加します。
public class Myclass : MarshalByRefObject
{
private string Text1;
private string Text2;
private int NoOfperson = 0 ;
private person[] List = new person [6];
public void setText1(string t)
{ Text1= t; }
public void setText2(string t)
{ Text2= t }
public string getText1 ()
{ return Text1; }
public string getText1 ()
{ return Text1; }
public int AddPerson (string name,string age)
{
person OBJ = new person ();
OBJ.Name = name;
OBJ.Age = age;
List[NoOfperson] = OBJ;
NoOfperson ++;
return NoOfperson - 1 ; //Index of current person
return 1 ;
}
public PersonStruct getPesrson(int index)
{
return PersonStruct.convertToStruct(List[index]);
}
}
人物クラス:
public class person
{
private string name;
private string age;
public string Age
{
get { return age; }
set { age = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}}
人の構造体:
public struct PersonStruct
{
public string name;
public string age;
public static PersonStruct convertToStruct(person OBJ)
{
PersonStruct tmp = new PersonStruct ();
tmp.name = OBJ.Name;
tmp.age = OBJ.Age;
return tmp;
}
person 配列の各要素を取得するには、オブジェクトをシリアル化しようとすると問題が発生するため、最初に構造体に変換します。とにかくこれは方法です:
public PersonStruct getPesrson(int index)
この方法では問題が発生しますが、スマート カードに正常に格納されます。これらの詳細で ArgumentOutOfRange Exception を取得しました。
Message
Index and length must refer to a location within the string.
TargetSite:
Void HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage
, System.Runtime.Remoting.Messaging.IMessage)
ParamName:
length
Source:
mscorlib
StackTrace:
Server stack trace:
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length,
Boolean fAlwaysCopy)
at System.String.Substring(Int32 startIndex, Int32 length)
at SmartCard.Runtime.Remoting.a.A(Type , String& , IMessage )
at SmartCard.Runtime.Remoting.a.a(Type , String& , IMessage )
at SmartCard.Runtime.Remoting.a.a(Type , String& , IMessage )
at SmartCard.Runtime.Remoting.a.A(Type , Byte[] , IMessage )
at SmartCard.Runtime.Remoting.a.A(Type , Stream , IMessage )
at SmartCard.Runtime.Remoting.Channels.APDU.APDUClientFormatterSink.SyncProce
ssMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
at medicalrecordApp.medicalrecord.getExamination(Int32 index)
at MyCompany.MyClientApp.MyClient.Main() in C:\Documents and Settings\User\My
Documents\Visual Studio 2008\Projects\Client2\Client2\MyClient.cs:line 36