After several frustrating hours troubleshooting issues with objects flowing in both directions (i.e., From Client to Sever and vice versa), I have some more information that may help you. This information is a continuation of the previous post on the subject found here.
In my previous posting I was primarily discussing activation of Client objects from a Server. I have also found something interesting about the communication between a Client and a Server over a remoting Channel, where a client object is accessed from a Server (i.e., not activated by the Server but proffered up from the Client to the Server over the remoting channel).
Is this confusing enough? Let’s use some pseudo-code to demonstrate the scenarios.
In the previous posting we spoke to the following scenerio.
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
System.Collections.IDictionary props = new System.Collections.Hashtable();
props["portName"] = “SomeName”;
ichannel = new IpcChannel(props, clientProvider, serverProvider);
…
RemotingServices.Marshal(ServerObject, @"UniqueIdentifier");
Or RegisterWellknownServiceType
ServerObject serverObj = (ServerObject)Activator.GetObject(Type.GetType(AssemblyQualifiedNameOfObject), @"ipc://" + @"UniqueIdentifier"+ @"/ServerObject"));
serverObj.CallAMethod();
In order to enable this two-way activation we need to set the typeFilterLevel to Full.
props["typeFilterLevel"] = "Full";
In the previous scenerio the Server can create MBRO’s and the Client can access the object methods over the channel. In a new scenerio, where the Client creates a MBRO object and attempts to pass the object to a Server Object, you will receive the following error message – “Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed.”
Note that this new scenerio the Server is not “activating” the Client object, but rather passing it to a Server object. Surprisingly, even though you have a channel established and you can call in one direction (Client calling on the Server), with an object that is MBRO, it fails. Doh!
We determined that we needed the typeFilterLevel property to be set to “Full” for the Server activating a Client object in the first scenerio. In this second scenerio, we also need to set the following;
serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
Go figure <shrug>
It is apparent that there is a difference between the
["typeFilterLevel"] = "Full" property
and
the Serverprovider setting
serverProvider.TypeFilterLevel = TypeFilterLevel.Full;