web dunia
web dunia

Reputation: 9929

How can I call a windows service in a console application?

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.

Upvotes: 0

Views: 1346

Answers (3)

wschenkai
wschenkai

Reputation: 185

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

Upvotes: 1

AgileJon
AgileJon

Reputation: 53596

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

Upvotes: 0

Ray Vernagus
Ray Vernagus

Reputation: 6150

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

Upvotes: 0

Related Questions