Solution to the "system. delegateserializationholder type is not allowed and the derived type (for example, system. delegateserializationholder) is deserialized at this security level" error.
In. NET Framework 1.1, the security level is low by default, so it cannot be deserialized. The following code is a chat program, which can be accessed after the configuration file is modified.
Remote Processing Program: 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 ("The Chat control object has been created. Instance: "+ this. gethashcode (). tostring ());
}
Public override object initializelifetimeservice (){
Return NULL;
}
Public event submissioneventhandler submission;
Public void submit (string contribution, string contributor ){
Console. writeline ("{0} sent: {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)
{
Remotingconfiguration. Configure ("Central. config ");
Console. writeline ("the service has been started. Press enter 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 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 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 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 red-colored parts are controlled by level
Full: Full deserialization level for. NET remote processing. It supports all types supported by remote processing in all cases.
Low: Low deserialization level for. NET remote processing. It supports types associated with Basic remote processing functions.
-->
<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 red-colored parts are controlled by level -->
<Serverproviders>
<Provider ref = "WSDL"/>
<Formatter ref = "Soap" typefilterlevel = "full"/>
<Formatter ref = "binary" typefilterlevel = "full"/>
</Serverproviders>
</Channel>
</Channels>
</Application>
</System. runtime. remoting>
</Configuration>
In the command prompt in this directory, type the following command to run:
CSC/T: Library chatcoordinator. CS
CSC/R: chatcoordinator. dll server. CS
CSC/R: chatcoordinator. dll client. CS