如何在控制台应用程序中调用 Windows 服务?

发布于 2024-07-25 10:32:20 字数 245 浏览 1 评论 0原文

我编写了一个 WCF 服务,我想将其称为网络管道绑定方式。 我已将其部署在 Windows 服务中。

我在我的 wcf 服务中编写了这个方法:

Add(2,1)

它应该返回 3

我不知道如何在我的客户端控制台应用程序中调用 Windows 中托管的服务。 我已经开始我的服务了。


注意:

我想从 Windows 服务中调用它。

I wrote a WCF service and I would like to call this the net pipe binding way. I have deployed this in a Windows service.

I wrote this method in my wcf service:

Add(2,1)

It should return 3

I don't know how to call the service hosted in windows in my client console application. I have started my service.


Note:

I would like to call this from a windows service.

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

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

发布评论

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

评论(3

奈何桥上唱咆哮 2024-08-01 10:32:20

需要使用ChannelFactory创建代理,然后就可以使用该代理执行wcf任务。

http://www.switchonthecode.com/tutorials/wcf-tutorial-基本进程间通信

you need to use ChannelFactory to create a proxy, and then you can use the proxy to perform wcf tasks.

http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication

雪若未夕 2024-08-01 10:32:20

如果 IMyContract 是您的服务合约,您可以创建一个代理来使用 ChannelFactory 类调用您的服务:

var proxy = ChannelFactory<IMyContract>.CreateChannel(new NetMsMqBinding(), new EndpointAddress("net.msmq://..."))
proxy.Add(1, 2);

If IMyContract is your service contract, you can create a proxy to call your service using the ChannelFactory class:

var proxy = ChannelFactory<IMyContract>.CreateChannel(new NetMsMqBinding(), new EndpointAddress("net.msmq://..."))
proxy.Add(1, 2);
小帐篷 2024-08-01 10:32:20

你想要这样的东西:

NetNamedPipeBinding binding = new NetNamedPipeBinding();
EndpointAddress address = new EndpointAddress("net.pipe://localhost/Foo");
ChannelFactory<IFoo> factory = 
    new ChannelFactory<IFoo>(binding, address);

IFoo foo = factory.CreateChannel();
int result = foo.Add(2, 1);

You want something like this:

NetNamedPipeBinding binding = new NetNamedPipeBinding();
EndpointAddress address = new EndpointAddress("net.pipe://localhost/Foo");
ChannelFactory<IFoo> factory = 
    new ChannelFactory<IFoo>(binding, address);

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