The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

MichaelZX6R636 (1) [Avatar] Offline
#1
When running listing 5.9, helloclientca3, I got the following exception:

"System.Security.SecurityException: Type System.Runtime.Remoting.Lifetime.ISponsor and the types derived from it (such as HelloSponsor) are not permitted to be deserialized at this security level."

I found the solution in an MSDN article: http://msdn2.microsoft.com/en-us/library/5dxse167.aspx

In order to fix the problem in 5.9 I made the following changes to "helloservice.exe.http.ca.config"...

...
<channels>
<channel >
ref="http"
port="6789">
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Low" />
</serverProviders>
</channel>
</channels>
...

I set the soap "typeFilterLevel" to Full to turn off the security and let the program deserialize more types. If there was a callback to your client you would need to make the same changes to the client's config file, but for this program everything should work fine with the changes above.

You can also configure the "TypeFilterLevel" inside your program when you create a channel object. Here I'll use the TCP channel and the binary formatter filter settings in 5.10, echoService.cs (don't forget to add the extra using statements)...

...
using System.Runtime.Remoting.Channels.Tcp;
using System.Collections;
using System.Runtime.Serialization.Formatters;

public class EchoService
{
public static void Main()
{
BinaryServerFormatterSinkProvider provider =
new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;

IDictionary props = new Hashtable();
props["port"] = 6789;

//register a channel...
ChannelServices.RegisterChannel(new TcpChannel(props, null, provider));

...

The program will still crash because of the callback to 5.12, echoClient.cs. Make the same changes to echoClient...
...
using System.Runtime.Remoting.Channels.Tcp;
using System.Collections;
using System.Runtime.Serialization.Formatters;

...

public class EchoClient
{
public static void Main()
{
BinaryServerFormatterSinkProvider provider =
new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;

IDictionary props = new Hashtable();
props["port"] = 0;


ChannelServices.RegisterChannel(new TcpChannel(props, null, provider));
EchoObj echoObjRef = (EchoObj)Activator.GetObject(
typeof(EchoObj),
"tcp://localhost:6789/EchoObj"
);
...

I hope this helps! If someone has a better fix, let me know. And thanks for the great book, Fergal!