程序是这样的:程序有客户端和服务器端,
在服务器端:用这样的语句注册了一个远程对象
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Publisher), "PublishSubscribe", WellKnownObjectMode.Singleton);在客户端:用这样的语句创建的一个远程对象,这样我在客户端就可以调用服务端的函数
NewPublisher = (Publisher)Activator.GetObject(typeof(Publisher), "tcp://localhost:8090/PublishSubscribe");在客户端:但是我现在把远程对象上的一个事件绑定,绑定的是一个客户端的函数
NewPublisher.OnUpdatedFakeTicker += new Publisher.PublishedTickerFunction(NewSubscriber.OnSubscriberUpdate);
也就是说服务器端响应某一函数时,调用客户端的NewSubscriber.OnSubscriberUpdate函数程序运行的时候总是在
NewPublisher.OnUpdatedFakeTicker += new Publisher.PublishedTickerFunction(NewSubscriber.OnSubscriberUpdate);
出错,没有绑定事件,
说是“不允许类型 System.DelegateSerializationHolder 和从中派生的类型(例如System.DelegateSerializationHolder)在此安全级别上被反序列化”有哪位高手做过这种在客户端创建远程对象,再绑定客户端的事件的功能的请给点指点拉,
最好是有个简单的试例。在下先在这里谢谢了!
在服务器端:用这样的语句注册了一个远程对象
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Publisher), "PublishSubscribe", WellKnownObjectMode.Singleton);在客户端:用这样的语句创建的一个远程对象,这样我在客户端就可以调用服务端的函数
NewPublisher = (Publisher)Activator.GetObject(typeof(Publisher), "tcp://localhost:8090/PublishSubscribe");在客户端:但是我现在把远程对象上的一个事件绑定,绑定的是一个客户端的函数
NewPublisher.OnUpdatedFakeTicker += new Publisher.PublishedTickerFunction(NewSubscriber.OnSubscriberUpdate);
也就是说服务器端响应某一函数时,调用客户端的NewSubscriber.OnSubscriberUpdate函数程序运行的时候总是在
NewPublisher.OnUpdatedFakeTicker += new Publisher.PublishedTickerFunction(NewSubscriber.OnSubscriberUpdate);
出错,没有绑定事件,
说是“不允许类型 System.DelegateSerializationHolder 和从中派生的类型(例如System.DelegateSerializationHolder)在此安全级别上被反序列化”有哪位高手做过这种在客户端创建远程对象,再绑定客户端的事件的功能的请给点指点拉,
最好是有个简单的试例。在下先在这里谢谢了!
BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; //this is important!!!
BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();IDictionary props = new Hashtable();
props["port"] = 1234;HttpChannel chan = new HttpChannel(props, clientProv, serverProv);
ChannelServices.RegisterChannel( chan );If you are setting up channels in config file, add following in formatter tag:
...
<formatter ref="soap" typeFilterLevel="Full" />
...
我按照你说的改了一下程序好向还是不行,能不能帮我看一下源代码啊,是哪里有问题,
我把所有的都发布上来//StatusEventArgs.cs
using System;namespace StatusEvent
{
[Serializable]
public class StatusEventArgs
{
private string message;
public StatusEventArgs()
{
}
public StatusEventArgs( string m )
{
message = m;
}
public string Message
{
get
{
return message;
}
set
{
message = value;
}
}
}
}
//EventSink.cs
using System;
using StatusEvent;
using System.Runtime.Remoting.Messaging;namespace Wrox.ProfessionalCSharp
{
public class EventSink:System.MarshalByRefObject
{
public EventSink()
{
} [OneWay]
public void StatusHandler( object sender, StatusEventArgs e)
{
Console.WriteLine("EventSink:Event occurred:" + e.Message);
}
}
}
//RemoteObject.cs
using System;
using StatusEvent;namespace Wrox.ProfessionalCSharp
{
public delegate void StatusEvent( object sender,StatusEventArgs e); public class RemoteObject:System.MarshalByRefObject
{
public RemoteObject()
{
Console.WriteLine("RemoteObject constructor called");
}
public event StatusEvent Status; public void LongWorking(int ms)
{
Console.WriteLine("RemoteObject:LongWorking()Started");
StatusEventArgs e = new StatusEventArgs(); //fire Event
if(Status != null)
{
Console.WriteLine("RemoteObject:Fire Starting Event");
Status(this,e);
}
System.Threading.Thread.Sleep(ms);
e.Message = "Message for Client:LongWorking()Ending"; //fire Ending
if(Status != null)
{
Console.WriteLine("RemoteObject:Fire Endinig Event");
Status(this,e);
}
Console.WriteLine("RemoteObject:LongWorking()Ending");
}
}
}
//server.cs服务端
using System;
using System.Runtime.Remoting;namespace Wrox.ProfessionalCSharp
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Server
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
RemotingConfiguration.Configure("Server.config");
Console.WriteLine("Hit to exit");
Console.ReadLine();
}
}
}
using System;
using System.Runtime.Remoting;namespace Wrox.ProfessionalCSharp
{
class Client
{
[STAThread]
static void Main(string[] args)
{
RemotingConfiguration.Configure("Client.config");
RemoteObject obj = new RemoteObject();
EventSink sink = new EventSink(); //register client sink in server . subscribe to event
obj.Status += new StatusEvent(sink.StatusHandler);
obj.LongWorking(5000); }
}
}
//Server.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="SingleCall" type="Wrox.ProfessionalCSharp.RemoteObject,RemoteObject" objectUri="Hi"/>
</service>
<channels>
<channel type="System.Runtime.Remoting.Channels.Tcp.TcpChannel, System.Runtime.Remoting" port="6791"/>
</channels>
<serverProviders>
<formatter ref="soap" typeFilterLevel="Full" />
</serverProviders>
</application>
</system.runtime.remoting>
</configuration>//Client.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<client>
<wellknown type="Wrox.ProfessionalCSharp.RemoteObject,RemoteObject" url="tcp://localhost:6791/Hi"/>
</client>
<channels>
<channel type="System.Runtime.Remoting.Channels.Tcp.TcpChannel,System.Runtime.Remoting"/>
</channels>
<serverProviders>
<formatter ref="soap" typeFilterLevel="Full" />
</serverProviders>
</application>
</system.runtime.remoting>
</configuration>