Remoting Obj Uri如何在用户端运行时生成? [英] How can Remoting Obj Uri be gernated at runtime at subscriber's end?

查看:58
本文介绍了Remoting Obj Uri如何在用户端运行时生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你好,


我正在使用.NET Remoting实现发布者/订阅者模式。为此我不想采用URI的每当新订阅者想要订阅发布者时,从配置文件开始,实际上只有一个进程,
将作为订阅者。但是当发布者想要将内容发布给订阅者时,它将从其数据结构中搜索其URI。


例如


,每次XYZ的实例订阅时,它必须携带其唯一的URI,该URI将添加到发布者的数据结构中,描述其身份作为uri。每当需要发布一些数据时,发布者就会使用这个URI。


问题是每次新实例启动和订阅时,都会从app.config中读取它的uri。 ,这将始终是新的XYZ实例启动(因为它是一个相同的进程,将访问相同的app.config,它只有
单个uri)。为此,我必须每次生成一个唯一的URI,实例启动,并且该远程控制环境可以知道该URI。


问候


Usman


解决方案

我已经考虑过了,没有考虑过找到问题的答案。


以下架构是否符合您的需求:


将服务器实现为单例(远程支持此功能)  并强制客户端使用id(可能是进程的PID)来标识自己。


public interface IRemotingServiceClient

{

       对象ClientID {get;}

}


公共接口IRemotingService

{

          public void DoAction()

}


 


public class RemotingServer:MarshalByReference

{

    Dictionnary< IRemotingServiceClient,IRemotingService> _serviceCache = new ...



    public void DoAction(IRemotingServiceClient client)

    {

          service = GetServiceFromCache(client);

          

          service.DoAction();   

    }


    private IRemotingService GetServiceFromCache(IRemotingServiceClient client)

   {

           //检查客户是否存在服务,如果需要,请创建一个服务并调用所需方法。

   }


   


}


 


Hello,

I am implementing publisher/subscriber pattern with the use of .NET Remoting.For this i don't want to take URI's from configuration file every time a new subscriber want to subscribe to publisher, As physically there's only a single process that will behave as subscriber. But when publisher want to publish the content to subscriber, it will search for its URI from its data structures.

e.g

let say there are 4 seperate processes having instances(XYZ_instance1,XYZ_instance2,XYZ_instance3,XYZ_instance4) launched of "XYZ.exe". Now publisher want's to publish the contents on XYZ_instance3(XYZ_instance3 would have its different uri).For this every time XYZ's instance is subscribing it must carry its unique URI, which will be added in publisher's data structure, describing about its identity as uri. Whenever some data needs to publish, publisher will use this URI.

The problem is every time a new instance is launching and subscribing, it will read its uri from app.config, which will be same all the time new instance of XYZ is started(as its a same process and will access the same app.config, which's just having single uri). FOR this i have to generate a unique URI every time, instance is started, and that URI whould be known by Remoting envirnment.

Regards

Usman

解决方案

I've thought about it and didn't come up with an answer to your problem.

Would the following architecure fit your needs:

Implement the server as a singleton (remoting supports this) and force the clients to identify themselves using an id (maybe the PID of the proces).

public interface IRemotingServiceClient
{
        object ClientID {get;}
}

public interface IRemotingService
{
         public void DoAction()
}

 

public class RemotingServer : MarshalByReference
{
    Dictionnary<IRemotingServiceClient, IRemotingService> _serviceCache = new...

    public void DoAction(IRemotingServiceClient client)
    {
         service = GetServiceFromCache(client);
         
         service.DoAction();   
    }

    private IRemotingService GetServiceFromCache(IRemotingServiceClient client)
   {
           // check if a service exists for the client, create one if needed and invoke the needed method.
   }

   

}

 


这篇关于Remoting Obj Uri如何在用户端运行时生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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