解决“不允许类型 System.DelegateSerializationHolder 和从中派生的类型(例如 System.DelegateSerializationHolder)在此安全级别上被反序列化”错误的办法。
来源:互联网 发布:mac重装找不到硬盘 编辑:程序博客网 时间:2024/04/29 09:18
解决“不允许类型 System.DelegateSerializationHolder 和从中派生的类型(例如 System.DelegateSerializationHolder)在此安全级别上被反序列化”错误的办法。
在.NET Framework 1.1中安全级别默认是Low的,所以不能被反序列化。以下代码是是一个聊天程序,在修改了配置文件后就可以访问了。
远程处理程序: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("聊天控制对象已经建立。 实例: " + this.GetHashCode().ToString());
}
public override object InitializeLifetimeService(){
return null;
}
public event SubmissionEventHandler Submission;
public void Submit(string contribution, string contributor){
Console.WriteLine("{0} 发送: {1}.", contributor, contribution);
SubmitEventArgs e = new SubmitEventArgs(contribution, contributor);
if (Submission != null){
Console.WriteLine("广播……");
Submission(this, e);
}
}
}
宿主应用程序:Server.cs
using System;
using System.Runtime.Remoting;
public class Server
{
public static void Main(string[] Args)
{
RemotingConfiguration.Configure("Central.config");
Console.WriteLine("服务已经启动。 按回车键退出。");
Console.ReadLine();
}
}
客户端应用程序: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("按0和回车键退出:/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("你的消息经被广播。。");
}
else
Console.WriteLine(args.Contributor + " 说: " + 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();
}
}
服务器端配置文件:Central.config
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="Singleton" type="ChatCoordinator, ChatCoordinator" objectUri="Chat" />
</service>
<channels>
<channel ref="http" port="8080">
<!--
以下红颜色的部分是控制按级别的
Full: .NET 远程处理的完全反序列化级别。它在所有情况下都支持远程处理所支持的全部类型。
Low: .NET 远程处理的低反序列化级别。它支持与基本的远程处理功能相关联的类型。
-->
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
客户端配置文件:Client.config
<configuration>
<system.runtime.remoting>
<application>
<client>
<wellknown type="ChatCoordinator, ChatCoordinator" url="http://localhost:8080/Chat" />
</client>
<channels>
<channel ref="http" port="0">
<!--以下红颜色的部分是控制按级别的-->
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
在该目录中的命令提示处,键入以下命令就可以运行了:
csc /t:library ChatCoordinator.cs
csc /r:ChatCoordinator.dll server.cs
csc /r:ChatCoordinator.dll client.cs
- 解决“不允许类型 System.DelegateSerializationHolder 和从中派生的类型(例如 System.DelegateSerializationHolder)在此安全级别上被反序列化”错误的办法。
- 不允许类型 System.DelegateSerializationHolder 和从中派生的类型(例如 System.DelegateSerializationHolder)在此安全级别上被反序列化
- Microsoft .NET Remoting权威指南中例子错误的解决(不允许类型 System.DelegateSerializationHolder 和从中派生的类型(例如 System.DelegateSerializationHolder)在此安全
- 解决“不允许类型 System.DelegateSerializationHolder 和从中派生的类型(例如 System
- 解决“无法将System.Byte[]的对象强制转换为类型System.IConvertible”的错误
- C#之解决 未处理的“System.InvalidOperationException”类型的异常出现在 System.dll中...
- 【C#】解决进行反序列化时出错:。InnerException 消息是“反序列化对象 属于类型 System.String 时出现错误。读取 XML 数据时,超出最大字符串内容长度配额 (8192)。
- 类型的序列化和反序列化
- “System.Web.HttpException”类型的异常在 System.Web.dll
- CS0012: 类型“System.Data.Objects.DataClasses.EntityObject”在未被引用的程序集中定义----问题解决办法
- 数据库在创建表语句的时候,出现:列在此处不允许错误的解决方法
- 错误:无法将类型为“System.DBNull”的对象强制转换为类型“System.Byte[]”。
- 【VC++类型转换】CString和System::String类型的转换
- 错误系列:列在此处不允许
- 解决vb.net 2003:未处理的“System.NullReferenceException”类型的异常出现在 system.data.dll 中
- 自制证书时报"此证书模板上的权限不允许当前用户注册此类型的证书"的解决办法
- 登陆失败:未授予用户在此计算机上的请求登陆类型 问题的解决
- 错误:类型“System.Data.EntityState”在未被引用的程序集中定义。必须添加对程序集“System.Data.Entity, Version=4.0.0.0, Culture=neu
- 未经整理的一些想法-关于人工智能
- 如何实现图像左右翻转[答网友]
- 一套C++练习题(含答案)供大家参考!作者:yaozheng
- 对面向对象,VC,C#的理解
- Socket API实现Trace Route
- 解决“不允许类型 System.DelegateSerializationHolder 和从中派生的类型(例如 System.DelegateSerializationHolder)在此安全级别上被反序列化”错误的办法。
- [转载]教你理解复杂的C-C++声明
- zz 面向对象编程,我的思想(上部)
- Visual .net 2002打开Visual .net 2003项目
- 是Iframe高度自适应
- 搞技术的如何尽快晋升
- asp20条
- Java名人录
- ASP编写完整的一个IP所在地搜索类