如何将发布者-订阅者配置包含在单个 app.config 中?
我正在编写一个简单的服务器(发布者)和客户端(订阅者)应用程序来想象两个托管 C# 进程之间的进程间通信。
我需要编写一个服务器(作为发布者),它将根据其订阅和客户端(订阅者)将内容发布给订阅者。为此,我必须在发布者端和订阅者端编写两个单独的配置文件 (app.config
)。
它正在制造一个问题。当发布者想要发布数据时,它使用 Process.Start
语句启动进程(作为订阅者工作的客户端)。启动时,客户端进程无法初始化远程处理,因为它加载了在服务器端使用的 app.config
,但它找不到自己的配置(订阅者的配置)。
我需要在单个 app.config
文件中写入订阅者和发布者配置。
我该怎么做呢?
I am writing a simple server (publisher) and client (subscriber) application to imagine inter-process communication between two managed C# processes.
I need to write a server (that's working as a publisher) that will publish the contents to the subscriber on the basis of its subscriptions and client (subscriber). For this I have to write two seperate configuration files (app.config
) on both the publisher's and subscriber's end.
It's creating a problem. When the publisher wants to publish the data, it starts the process (client which is working as subscriber) with Process.Start
statement. On start, the client process is unable to initialize remoting because it loads app.config
which is being used on the server side, where it didn't find its own configurations (subscriber's configurations).
I need to write both subscriber and publisher configuration on a single app.config
file.
How do I go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发布者和订阅者是否在同一个exe下运行?如果没有,那么您可以使用特定于应用程序的配置文件(.config)而不是“app.config”。
来自 MSDN:
您可以将连接信息放在此处,并指定 Process.Start 的 StartInfo,并确保指定应用程序的启动位置。这应该会强制它从该目录中的配置文件中读取。
Are the publisher and subscriber running under the same exe? If not, then you can use application specific config files (.config) rather than "app.config".
From MSDN:
You can put the connection info here, and specify the StartInfo for the Process.Start and make sure you specify where the app is launched from. That should force it to read from the config file in that directory.