Tutorials to .com

Tutorials to .com » Dotnet » Winform » Solution "does not allow the type System.DelegateSerializationHolder and derived from the type (for example, System.DelegateSerializationHolder) at this security level by the anti -

Solution "does not allow the type System.DelegateSerializationHolder and derived from the type (for example, System.DelegateSerializationHolder) at this security level by the anti -

Print View , by: iSee ,Total views: 12 ,Word Count: 899 ,Date: Tue, 25 Aug 2009 Time: 4:09 PM

Solution "does not allow the type System.DelegateSerializationHolder and derived from the type (for example, System.DelegateSerializationHolder) at this security level by the anti-sequence" of the wrong approach.
In the. NET framework 1.1 in the default security level is Low, so can not be deserialized. The following code is a chat program, after modifying the configuration files can be accessed.


Remote handling procedures: ChatCoordinator.cs

using System;
using System.Runtime.Remoting;
using System.Collections;

[Serializable]
public class SubmitEventArgs: EventArgs (

private string _string = null;
private string _alias = null;

public SubmitEventArgs (string contribution, string contributor) (
this._string = contribution;
this._alias = contributor;
)

public string Contribution (
get (
return _string;
)
)

public string Contributor (
get (
return _alias;
)
)
)

public delegate void SubmissionEventHandler (object sender, SubmitEventArgs submitArgs);

public class ChatCoordinator: MarshalByRefObject (

public ChatCoordinator () (
Console.WriteLine ( "chat with the control object has been created. Examples:" + this.GetHashCode (). ToString ());
)
public override object InitializeLifetimeService () (
return null;
)
public event SubmissionEventHandler Submission;

public void Submit (string contribution, string contributor) (
Console.WriteLine ( "(0) send: (1).", Contributor, contribution);

SubmitEventArgs e = new SubmitEventArgs (contribution, contributor);

if (Submission! = null) (
Console.WriteLine ( "Broadcasting ... ...");
Submission (this, e);
)
)
)

Host Application: Server.cs

using System;
using System.Runtime.Remoting;

public class Server
(
public static void Main (string [] Args)
(
RemotingConfiguration.Configure ( "Central.config");
Console.WriteLine ( "service has been launched. Press Enter key to exit.");
Console.ReadLine ();
)
)

Client application: client.cs

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class ChatClient: MarshalByRefObject (

private string username = null;

public override object InitializeLifetimeService () (
return null;
)

public ChatClient (string alias) (

this.username = alias;

)

public void Run () (

RemotingConfiguration.Configure ( "Client.config");
ChatCoordinator chatcenter = new ChatCoordinator ();
chatcenter.Submission + = new SubmissionEventHandler (this.SubmissionReceiver);
String keyState = "";

while (true) (
Console.WriteLine ( "Press 0 and Enter key to exit: \ r \ n");
keyState = Console.ReadLine ();

if (String.Compare (keyState, "0", true) == 0)
break;
chatcenter.Submit (keyState, username);
)
chatcenter.Submission -= new SubmissionEventHandler (this.SubmissionReceiver);
)

public void SubmissionReceiver (object sender, SubmitEventArgs args) (

if (String.Compare (args.Contributor, username, true) == 0) (
Console.WriteLine ( "Your message has been broadcast by the 。。");
)
else
Console.WriteLine (args.Contributor + "says:" + args.Contribution);
)

public static void Main (string [] Args) (

if (Args.Length! = 1) (
Console.WriteLine ( "You need to type an alias.");
return;
)

ChatClient client = new ChatClient (Args [0]);
client.Run ();
)
)

Server-side configuration file: Central.config

<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="Singleton" type="ChatCoordinator, ChatCoordinator" objectUri="Chat" />
</ service>
<channels>
<channel ref="http" port="8080">
"! --
The following part is to control the red color according to level of
Full:. NET Remoting complete deserialization level. It is supported in all cases supported by remote processing of all types.
Low:. NET remoting serialization of the low level of anti-. It supports remote processing and basic associated type.
- "
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</ serverProviders>
</ channel>
</ channels>
</ application>
</ system.runtime.remoting>
</ configuration>

Client configuration file: Client.config

<configuration>
<system.runtime.remoting>
<application>
<client>
<wellknown type="ChatCoordinator, ChatCoordinator" url=" http://localhost:8080/Chat "/>
</ client>
<channels>
<channel ref="http" port="0">
"! - The following part is to control the red color according to level of -"
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</ serverProviders>
</ channel>
</ channels>
</ application>
</ system.runtime.remoting>
</ configuration>

In the directory the command prompt, type the following command can be run:

csc / t: library ChatCoordinator.cs

csc / r: ChatCoordinator.dll server.cs

csc / r: ChatCoordinator.dll client.cs



.Net Windows development Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.