WPF 应用程序中的 WCF 命名管道

发布于 2024-07-25 01:29:00 字数 462 浏览 6 评论 0原文

如何在 WPF Windows 应用程序后台运行 WCF 命名管道服务? 我似乎找不到在 WPF 应用程序中运行 WCF 服务器的任何示例。

有任何想法吗?

我目前在 Application_Startup 中使用以下代码。 这需要用它自己的线程运行吗?

    Using Host As ServiceModel.ServiceHost = New ServiceModel.ServiceHost(GetType(Service), New Uri(("net.pipe://localhost")))
        '
        Host.AddServiceEndpoint(GetType(IService), New ServiceModel.NetNamedPipeBinding, "Test")
        Host.Open()
        '
    End Using

How would you run a WCF named pipe service in the background of a WPF Windows application? I can't seem to find any samples of running the WCF server within a WPF application.

Any ideas?

I am currently using the following code in the Application_Startup. Does this need to run with it's own thread?

    Using Host As ServiceModel.ServiceHost = New ServiceModel.ServiceHost(GetType(Service), New Uri(("net.pipe://localhost")))
        '
        Host.AddServiceEndpoint(GetType(IService), New ServiceModel.NetNamedPipeBinding, "Test")
        Host.Open()
        '
    End Using

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

优雅的叶子 2024-08-01 01:29:00

Juval Lowy 在他的 ServiceModelEx 库中提供了帮助程序类,以及有关如何在进程中运行 WCF 组件的信息,这可能是您想要对 WCF 组件执行的操作,因为您想要使用需要该组件的命名管道与您的 WPF 应用程序在同一台计算机上运行。

我建议从“编程 WCF 服务”第二版的第 60 页开始阅读有关 InProcFactory 类的内容作者:朱瓦尔·洛伊。 这实质上是WCF的“圣经”。

这将准确地向您展示如何使用他的帮助器类来托管进程中的组件。

Juval Lowy provides helper classes in his ServiceModelEx library along with information on how to run WCF components in-process, which is probably what you're going to want to do with your WCF component since you want to use named-pipes which requires the component to be running on the same machine as your WPF app.

I suggest reading about the InProcFactory class starting on page 60 of the 2nd Edition of "Programming WCF Services" by Juval Lowy. This is essentially the "bible" of WCF.

This will show you exactly how to host your component in process using his helper classes.

缱绻入梦 2024-08-01 01:29:00

我删除了使用代码块并将 ServiceHost 设置为 WPF 应用程序类中的私有变量。 然后,当应用程序退出时,我关闭 ServiceHost。 似乎工作正常。

I removed the Using code block and setup the ServiceHost as a private variable within the WPF Application class. I then close the ServiceHost when the application exits. Seems to work fine.

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