Sunny
7/16/2004 8:12:00 PM
Now thats OK. The error message and the code are enough for now.
There are some issues:
1. You have to set the typeFilterLevel property to Full both at the
server and at the client. This enables custom types to be passed. And
you will not receive that exception. Your channel registration should
look like:
BinaryServerFormatterSinkProvider srvFormatter = new
BinaryServerFormatterSinkProvider();
srvFormatter.TypeFilterLevel = TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clntFormatter =
new BinaryClientFormatterSinkProvider();
IDictionary props = new HashTable();
props["port"] = 9999;
TcpChannel chan1 = new TcpChannel(props, clntFormatter, srvFormatter);
2. Actually this is not your original problem, right? You said that your
ArrayList contains MBR objects, while your sample is with strings. This
is completely different, as strings are passed by value.
3. In your SetArray method you do not need to use Clone(). As ArrayList
is not MBR, and it is [Serializable], its copy will be passed on the
wire, not a reference to it.
4. If some of the objects in the ArrayList are MBRs, then only reference
to them will be passed to the server. In order that server can access
them, you have to have listening channel at the client side as well,
otherwise the server will fail to connect to the actual objects on the
client. This means that you can not use the silent channel registration
like now (directly using Activator.GetObject). You have to register a
TcpChannel at the client as well. There you soul use port = 0, allowing
the system to choose a free port for you.
Hope that helps
Sunny
In article <1F804467-DB7A-415E-90CB-51E5A3E76595@microsoft.com>,
bfrench@discussions.microsoft.com says...
> Ok, now I've got a sample program with a Class library that I use for remoting, a server component and a client component. I get a more specific error now which is:
>
> An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
> Additional information: Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed.
>
> Now as for attaching the program, I'm accessing this newsgroup from MS's msdn site which apparently doesn't allow attachments. I'm at work and I don't have access to this group on our news server....so I hope no one minds, but I'll post the code here for each component.
>
> The class library contains two files, named Class1.cs and Class2.cs:
> Class1.cs:
>
> using System;
> using System.Collections;
>
> namespace RemoteIssue
> {
> public class Class1 : MarshalByRefObject
> {
> private ArrayList arrLstClass2;
> private string teststring;
>
> public Class1()
> {
> teststring = "This is a test";
> }
>
> public void SetArrayList(ArrayList arr)
> {
> arrLstClass2 = (ArrayList)arr.Clone();
> }
>
> public ArrayList ArrayListClass2
> {
> get
> { return arrLstClass2; }
> set
> { arrLstClass2 = value; }
> }
>
> public string TestString
> {
> get
> { return teststring; }
> set
> { teststring = value; }
> }
> }
> }
>
> Class2.cs:
>
> using System;
> using System.Collections;
>
> namespace RemoteIssue
> {
> public class Class2 : MarshalByRefObject
> {
> private ArrayList arrLstStrings;
>
> public Class2()
> {
> arrLstStrings = new ArrayList();
> }
>
> public ArrayList ArrayListStrings
> {
> get
> { return arrLstStrings; }
> set { arrLstStrings = value; }
> }
> }
> }
>
>
> The server component contains one file: Server.cs and references the above library and System.Runtime.Remoting
>
> using System;
> using System.Runtime.Remoting;
> using System.Runtime.Remoting.Channels;
> using System.Runtime.Remoting.Channels.Tcp;
> using RemoteIssue;
>
> namespace Server
> {
> class Class1
> {
> [STAThread]
> static void Main(string[] args)
> {
> TcpChannel chan1 = new TcpChannel(9999);
> ChannelServices.RegisterChannel(chan1);
> RemotingConfiguration.RegisterWellKnownServiceType(
> typeof(RemoteIssue.Class1), "Class1", WellKnownObjectMode.Singleton);
> Console.WriteLine("Press Enter to end");
> Console.ReadLine();
> }
> }
> }
>
>
> And finally, the Client references the above library, and the code is as follows:
>
> using System;
> using System.Collections;
>
> namespace Client
> {
> class ClientClass
> {
> [STAThread]
> static void Main(string[] args)
> {
> ArrayList class2Arr = new ArrayList();
> RemoteIssue.Class1 c1;
> RemoteIssue.Class2 c2a = new RemoteIssue.Class2();
> RemoteIssue.Class2 c2b = new RemoteIssue.Class2();
>
> c2a.ArrayListStrings.Add("Hello");
> c2a.ArrayListStrings.Add("There");
> c2b.ArrayListStrings.Add("This is");
> c2b.ArrayListStrings.Add("fun!");
>
> class2Arr.Add(c2a);
> class2Arr.Add(c2b);
>
> //Here's where I enter my machine name and port for the server
> c1 = (RemoteIssue.Class1)Activator.GetObject(
> typeof(RemoteIssue.Class1), "tcp://sfa10006xp:9999/Class1");
>
> Console.WriteLine(c1.TestString);
>
> /* Both of these following lines fail with the error message:
> * An unhandled exception of type 'System.Runtime.Serialization.SerializationException'
> * occurred in mscorlib.dll
> * Additional information: Because of security restrictions,
> * the type System.Runtime.Remoting.ObjRef cannot be accessed.
> */
> c1.SetArrayList(class2Arr);
> c1.ArrayListClass2 = class2Arr;
> }
> }
> }
>
> Again, sorry for having to post the code and not being able to attach anything. I appreciate any help!
>
> bfrench
>