Solve "Do not allow type System.DelegateSerizationHolder and the type of derivation" (for example, System.DelegateSeri

xiaoxiao2021-03-06  20

Solve "Do not allow type System.DelegateSerizationHolder and the type of derivation" (for example, System.DelegateSerizationHold) is reversed in this security level. The security level in .NET Framework 1.1 is LOW by default, it is not possible to be defined. The following code is a chat program that can be accessed after modifying the configuration file.

Remote handler: chatcoordinator.cs

Using system.runtime.remoting; using system.collections;

[Serializable] public class submitAndargs: Eventargs {

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

Public SubmiteventArgs (String Contribution, String Contributor) {this._string = control; this._alias = contributor;

Public String Contribution {get {return _string;}}

Public string controlor {get {return _ALIAS;}}}

Public Delegate Void SubmissionEventHndrandler (Object Sender, SubmitEventArgs Submitargs);

Public class chatcoordinator: MarshalByrefObject {

public ChatCoordinator () {Console.WriteLine ( "chat control object instance has been established:.". this.GetHashCode () ToString ());} public override object InitializeLifetimeService () {return null;} public event SubmissionEventHandler Submission;

Public void submit (string control) {console.writeline ("{0} Send: {1}.", Contributor, Contribution;

SubmiteventArgs E = New SubmiteventArgs (Contribution, Contributor);

IF (Submission! = null) {console.writeLine ("broadcast ..."); Submission (this, e);}}}

Host application: Server.cs

Using system; using system.runtime.remoting;

Public class server {public static void main (string [] args) {recotingconfiguration.configure ("Central.config"); console.writeline ("The service is started. Press the Enter key to exit."); console.readline (); }

Client Application: Client.cs

Using system; using system.Runtime.remoting; system.Runtime.Remoting.Channels; use 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: / 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 is broadcast ..");} else console.writeline (args.contributor "said:" 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

client profile: client.config

in this directory The command prompt, type the following command, you can run:

CSC / T: library chatcoordinator.cs

CSC /R :Chatcoordinator.dll Server.cs

CSC /R :Chatcoordinator.dll Client.cs

转载请注明原文地址:https://www.9cbs.com/read-43297.html

New Post(0)