在.NET远程什么RemotingConfiguration.RegisterWellKnownServiceType和RemotingServices.Marshal之间的区别? [英] In .NET remoting what is the difference between RemotingConfiguration.RegisterWellKnownServiceType and RemotingServices.Marshal?

查看:850
本文介绍了在.NET远程什么RemotingConfiguration.RegisterWellKnownServiceType和RemotingServices.Marshal之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.NET远程什么RemotingConfiguration.RegisterWellKnownServiceType和RemotingServices.Marshal之间的区别?

我想要做的就是创建一个Windows服务的对象,然后把它作为一个远程对象,并有Windows服务和客户端的远程对象的双方行为。

我想下面的code会做到这一点。

  FooRemoting富=新FooRemoting();

RemotingConfiguration.RegisterWellKnownServiceType(typeof运算(FooRemoting)中servername,WellKnownObjectMode.Singleton);
RemotingServices.Marshal(富);
 

解决方案

这是我发现了什么。

  RemotingConfiguration.RegisterWellKnownServiceType(typeof运算(FooRemoting)
          servername,请将WellKnownObjectMode.Singleton);
 

RegisterWellKnownServiceType将创建对象,并使其一个Singleton到消耗它的任何客户机,但不创建一个参考由服务器。对象不创建直到客户端询问它,并且同一个对象被用于任何其他客户端。

  RemotingServices.Marshal(富);
 

元帅将注册已经由服务器创建的,在这种情况下,一个窗口服务的对象。然后服务器将具有参考对象和客户端将消耗同一对象

我的问题是用元帅来注册远程对象。随着时间的推移远程对象将消失,为客户消费,即不再对远程对象。该服务将仍然保持其基准。 然后我尝试了RegisterWellKnownServiceType和客户不断收到正确的引用,但我无法得到的服务有一个参考同一个对象。

该解决方案覆盖在这种情况下FooRemoting的远程对象。如果我重写了InitializeLifetimeService返回null,则客户将永远不会失去连接,该服务将, 保持连接。

 公众覆盖对象InitializeLifetimeService()
{
    //返回base.InitializeLifetimeService();
    返回null;
}
 

为了保持由服务创建的对象,并必须使用,必须使用相同的对象的客户机

  RemotingServices.Marshal(富);
 

和重载InitializeLifetimeService返回空值。

In .NET remoting what is the difference between RemotingConfiguration.RegisterWellKnownServiceType and RemotingServices.Marshal?

What I want to do is create an object in a Windows Service, then put it in as a remoting object and have the Windows Service and the Client both act on the remoting object.

I thought the below code would accomplish this.

FooRemoting foo = new FooRemoting();

RemotingConfiguration.RegisterWellKnownServiceType(typeof(FooRemoting), serverName, WellKnownObjectMode.Singleton);
RemotingServices.Marshal(foo);

解决方案

This is what I found.

RemotingConfiguration.RegisterWellKnownServiceType(typeof(FooRemoting), 
          serverName, WellKnownObjectMode.Singleton);

RegisterWellKnownServiceType will create the object and make it a Singleton to any client that consumes it, but a reference by the server is not created. The object is not created until a client ask for it, and the same object is used for any other clients.

RemotingServices.Marshal(foo);

Marshal will register an object that has been created by the server, in this case a windows service. Then server will then have reference to the object and the clients will consume the same object.

My issue was using the Marshal to register the remoting object. Over time the remoting object will disappear for clients to consume, i.e. no longer on the remoting object. The service would still keep its reference. Then I tried the RegisterWellKnownServiceType and the clients keep getting the correct reference, however I could not get the service to have a reference to the same object.

The solution is overriding the remoting object in this case FooRemoting. If I overrode the InitializeLifetimeService and returned null, the client would never lose connection, and the service will, keep the connection.

public override object InitializeLifetimeService()
{
    //return base.InitializeLifetimeService();
    return null;
}

In order to keep the object created by the service and have the client to use the same object you must use

RemotingServices.Marshal(foo);

and override InitializeLifetimeService to return null.

这篇关于在.NET远程什么RemotingConfiguration.RegisterWellKnownServiceType和RemotingServices.Marshal之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆