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

时间:2022-05-05 00:39:13

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.

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

I wrote this method in my wcf service:

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

Add(2,1)

It should return 3

它应该返回3

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

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


Note:

I would like to call this from a windows service.

我想从Windows服务中调用它。

3 个解决方案

#1


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

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

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

#2


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

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

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

#3


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);

#1


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

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

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

#2


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

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

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

#3


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);