如何将发布者-订阅者配置包含在单个 app.config 中?

发布于 2024-10-16 11:25:30 字数 397 浏览 5 评论 0原文

我正在编写一个简单的服务器(发布者)和客户端(订阅者)应用程序来想象两个托管 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛夏已如深秋| 2024-10-23 11:25:30

发布者和订阅者是否在同一个exe下运行?如果没有,那么您可以使用特定于应用程序的配置文件(.config)而不是“app.config”。

来自 MSDN:

由可执行主机托管的应用程序的配置文件与应用程序位于同一目录中。配置文件的名称是带有 .config 扩展名的应用程序的名称。例如,名为 myApp.exe 的应用程序可以与名为 myApp.exe.config 的配置文件关联。

您可以将连接信息放在此处,并指定 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:

The configuration file for an application hosted by the executable host is in the same directory as the application. The name of the configuration file is the name of the application with a .config extension. For example, an application called myApp.exe can be associated with a configuration file called myApp.exe.config.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文