Reputation: 25
I have .Net smart card and I am using c# to build the card application and the host application. Actually the smart card acts as a server in .Net remoting.
In smart card, I have remote object (Myclass) and I call remote method :
public int AddPerson (string name,string age)
to add some information to this object.
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]);
}
}
person class:
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; }
}}
PersonStruct:
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;
}
To retrieve each element of person array, I firstly convert it to struct because there are some problem when I try to serialize the object. Anyway this is the method :
public PersonStruct getPesrson(int index)
The problem is raised in this method, although they are stored successfully in the smart card. I got ArgumentOutOfRange Exception with these details:
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
Upvotes: 0
Views: 748
Reputation: 18549
It sounds like you are using SubString
with an index that doesn't exist in the string. You'd need to make sure your string has enough characters before using that index.
If this is a new project have a look at WCF instead of remoting, you might find it more suitable. Microsoft has published the following diagram:
Upvotes: 2