在VS2005里用Remoting通讯,出现“不允许类型System.DelegateSerializationHolder和从中派生的类型在此安全级别上被反序列化”的提示,在网络寻求帮助时,大部分都是在配置文件里加入: 
  <serverProviders> 
                        <provider   ref= "wsdl "   /> 
                        <formatter   ref= "soap "   typeFilterLevel= "Full "   /> 
                        <formatter   ref= "binary "   typeFilterLevel= "Full "   /> 
  </serverProviders> 但这好象是VS2003里的,VS2005里面不支持,问题还是解决不了。有没有在VS2005里面用过的帮忙支个招 ,
在代码中  BinaryServerFormatterSinkProvider serverProvider = new  BinaryServerFormatterSinkProvider();
            BinaryClientFormatterSinkProvider clientProvider = new  BinaryClientFormatterSinkProvider();
            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
                        IDictionary props = new Hashtable();
            props["port"] = 8080;
            HttpChannel channel = new HttpChannel(props, clientProvider, serverProvider);
            ChannelServices.RegisterChannel(channel);
应该是vs2005配置文件的问题,请问如何解决?

解决方案 »

  1.   

    http://topic.csdn.net/u/20110521/21/aa5aa25d-f593-4768-a0c9-24c6ace443a9.html?seed=1806195254&r=73447535#r_73447535这个帖子有详细的代码。
      

  2.   

    厄特意做了个例子,我的没问题厄(Single,CAO 都可以) 推荐使用CAO,每个客户端对应一个服务端实例。下面的实例是CAO(Client Activated Object)RemotingObjLibnamespace RemotingObjLib
    {
        public class RemotingObj : MarshalByRefObject
        {
            public event Action<string> CallbackEvent;        public void CallServerTask()
            {
                // Server Do Sth 在服务端输出
                Console.WriteLine("Server Do Sth ...");
                if (CallbackEvent != null)
                    CallbackEvent("Server callback ...");
            }
        }    public class EventWrapper : MarshalByRefObject
        {
            public event Action<string> ClientCallbackEvent;        public void ClientCallback(string msg)
            {
                if (ClientCallbackEvent != null)
                    ClientCallbackEvent(msg);
            }
        }
    }-----------------------------------
    服务端: class Program
     {
         static void Main(string[] args)
         {
             string config = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
             RemotingConfiguration.Configure(config);
             Console.WriteLine("Server is running...");
             Console.ReadLine();
         }
     }服务端配置<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.runtime.remoting>
        <application>
          <service>
            <activated  type="RemotingObjLib.RemotingObj, RemotingObjLib" />
          </service>
          <channels>
            <channel ref="tcp" port="33000">
              <serverProviders>
                <formatter ref="binary" typeFilterLevel="Full" />
              </serverProviders>
            </channel>
          </channels>
        </application>
      </system.runtime.remoting>
    </configuration>-----------------------------------
    客户端public class Program
    {
        static void Main(string[] args)
        {        Console.WriteLine("Client is running...");
            string config = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            RemotingConfiguration.Configure(config);
            RemotingObjLib.RemotingObj server = new RemotingObjLib.RemotingObj();
            RemotingObjLib.EventWrapper wrapper = new RemotingObjLib.EventWrapper();
            server.CallbackEvent += wrapper.ClientCallback;
            wrapper.ClientCallbackEvent += new Action<string>(wrapper_ClientCallbackEvent);        server.CallServerTask();
            Console.ReadLine();
        }    static void wrapper_ClientCallbackEvent(string obj)
        {
            Console.WriteLine("Client: " + obj); 
        }
    }客户端配置
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.runtime.remoting>
        <application>
          <client url="tcp://localhost:33000/" >
            <!--<wellknown
              type="RemotingObjLib.RemotingObj, RemotingObjLib"
              url="tcp://localhost:33000/CallbackSample" />-->
            <activated  type="RemotingObjLib.RemotingObj, RemotingObjLib" />
          </client>
          <channels>
            <channel ref="tcp" port="0">
              <clientProviders>
                <formatter ref="binary" />
              </clientProviders>
              <serverProviders>
                <formatter ref="binary" typeFilterLevel="Full" />
              </serverProviders>
            </channel>
          </channels>
        </application>
      </system.runtime.remoting>
    </configuration>启动2个客户端,服务端显示:(其实分别是两个Server实例)
    Server is running...
    Server Do sth ...      
    Server Do sth ...       2个客户端分别显示:
    Client is running...
    Client: Server callback ...如果改为Single的话,就不一样了。single适合做广播。
      

  3.   

    哦,对了,又看了看你的配置,感觉是你用了http的协议的问题。简单来说http是不支持双工通信的。在WCF中也是通过建立两条Http连接来实现双工回调的。建议改为tcp协议再试试。
      

  4.   

    把你的代码复制调试了,没有问题。但是原来的修改了一下,还是同样的问题。
    RemoteEventObject:
    using System;
    using System.Collections.Generic;
    using System.Text;namespace RemoteEventObject
    {
        //public delegate void StatusEvent(object sender, StatusEventArgs e);    
        
        public class RemoteObject : MarshalByRefObject
        {
            public RemoteObject()
            {
                Console.WriteLine("RemoteObject constructor called");
            }
            //public event StatusEvent Status;
            public event Action<string> Status;
                    public void LongWorking(int ms)
            {
                Console.WriteLine("RemoteObject:LongWorking() Started");
                //StatusEventArgs e = new StatusEventArgs("Message for Client:LongWorking() Started");            if (Status != null)
                {
                    Console.WriteLine("RemoteObject:Firing Starting Event");
                    //Status(this, e);
                    Status("Message for Client:LongWorking() Started");
                }
                System.Threading.Thread.Sleep(ms);
                //e.Message = "Message for Client:Long Working() Ending";
                //fire ending event
                if (Status != null)
                {
                    Console.WriteLine("RemoteObject:Firing Ending Event");
                    //Status(this, e);
                    Status("Message for Client:Long Working() Ending");
                }
                Console.WriteLine("RemoteObject:LongWorking() Ending");
            }
        }    //[Serializable]
        //public class StatusEventArgs
        //{
        //    private string message;    //    public StatusEventArgs(string m)
        //    {
        //        message = m;
        //    }    //    public string Message
        //    {
        //        get
        //        {
        //            return message;
        //        }
        //        set
        //        {
        //            message = value;
        //        }
        //    }
        //}
        
        public class EventSink : MarshalByRefObject
        {
            public EventSink()
            { }        //public void StatusHandler(object sender, StatusEventArgs e)
            //{
            //    Console.WriteLine("EventSink:Event occurred:" + e.Message);
            //}
            //public void StatusHandler(string e)
            //{
            //    Console.WriteLine("EventSink:Event occurred:" + e);
            //}        public event Action<string> StatusHandler;        public void StatusHandlerTest(string e)
            {
                if (StatusHandler != null)
                {
                    StatusHandler(e);
                }
                //Console.WriteLine("EventSink:Event occurred:" + e);
            }
        }
    }服务器端: static void Main(string[] args)
            {
                string filename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
                RemotingConfiguration.Configure(filename);//使用配置文件,配置文件采用的activate模式
                
                Console.WriteLine("press return to exit");
                Console.ReadLine();
            }服务端配置:<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.runtime.remoting>
        <application name="CallBackSample">
          <service>
            <activated type="RemoteEventObject.RemoteObject,RemoteEventObject"/>
          </service>
          <channels>
            <channel ref="tcp" port="33000"/>
            <serverProviders>
              <formatter ref="binary" typeFilterLevel="Full" />
            </serverProviders>
            <clientProviders>
              <formatter ref="binary" />
            </clientProviders>
          </channels>
        </application>  
      </system.runtime.remoting>
    </configuration>客户端: static void Main(string[] args)
            {
                string filename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
                RemotingConfiguration.Configure(filename);
               
               
                RemoteObject obj = new RemoteObject();
                EventSink sink = new EventSink();
                //RemoteObject.RemoteObject obj = (RemoteObject.RemoteObject)Activator.GetObject(typeof(RemoteObject.RemoteObject), "http://localhost:8080/BroadCastMessage.soap"); //new RemoteObject.RemoteObject();第一种方式            obj.Status += sink.StatusHandlerTest;
                sink.StatusHandler += new Action<string>(StatusHandlerClient);
                //obj.Status += new RemoteObject.RemoteObject.StatusEvent(sink.StatusHandler);
                obj.LongWorking(200);
                //obj.Status -= new Action<string>(sink.StatusHandler);
                //obj.Status -= new RemoteObject.RemoteObject.StatusEvent(sink.StatusHandler);
                obj.LongWorking(200);            Console.WriteLine("press return to exit");
                Console.ReadLine();
            }
            static void StatusHandlerClient(string e)
            {
                Console.WriteLine("EventSink:Event occurred:" + e);
            }
    客户端配置:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.runtime.remoting>
        <application name="Client">
          <client url="tcp://localhost:33000/CallBackSample">
            <activated type="RemoteEventObject.RemoteObject,RemoteEventObject"/>
          </client>
          <channels>
            <channel ref="tcp" port="0"/>
            <clientProviders>
              <formatter ref="binary" />
            </clientProviders>
            <serverProviders>
              <formatter ref="binary" typeFilterLevel="Full" />
            </serverProviders>
          </channels>
        </application>
      </system.runtime.remoting>
    </configuration>
      

  5.   

    代码基本是按你的例子改的,还是同样的错误,客户端运行到obj.Status += sink.StatusHandlerTest;这时候报错,不知道啥原因。反正正确的例子对照你的已经可以写了,谢谢了!!