我有 .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 数组的每个元素,我首先将其转换为 struct,因为在尝试序列化对象时出现了一些问题。无论如何,这是方法:
public PersonStruct getPesrson(int index)
尽管它们已成功存储在智能卡中,但此方法会出现问题。我得到了带有以下详细信息的 ArgumentOutOfRange 异常:
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