Nickolodeon
Nickolodeon

Reputation: 2956

self host wcf add service reference

So I created winforms client and added wcf class library to the solution.

In winforms I do

ServiceHost svc = new ServiceHost(typeof(...), new Uri("net.pipe://localhost/MyNamedPipe")

and then svc.Open() which executes fine.

Now, how do I add a service reference so in same winforms I can get proxy for that wcf?

I only was able to generate that by using ASP.NET Development Server which started when winforms was ran and so I copied that url, stopped debugging (Development Server was still running) and then added a service reference from there. But that isn't correct I guess.

Of course I can reference wcf contract class directly and use it, but that is not proper either.

Upvotes: 3

Views: 2156

Answers (2)

competent_tech
competent_tech

Reputation: 44921

Have you tried adding a Service Reference... to the project, then entering your URI directly in the Address box of the dialog?

Note that this should be the complete URI, such as net.pipe://localhost/MyNamedPipe.

You can find step-by-step instructions from MSDN here.

Upvotes: 1

Russell McClure
Russell McClure

Reputation: 4851

When you are controlling both ends like that, I prefer to use ChannelFactory:

NetNamedPipeBinding binding = new NetNamedPipeBinding();
EndpointAddress address = new EndpointAddress("net.pipe://localhost/MyNamedPipe");
ChannelFactory<YourInterface> factory = new ChannelFactory<YourInterface>(binding, address);
YourInterface yourInterface = factory.CreateChannel();

Upvotes: 4

Related Questions