BCS
BCS

Reputation: 78683

How to dynamically select the URI for a WCF service?

I'm trying to construct a WCF client object using a run time URI string. This seems simple enough but I'm running out of thing to try that don't seem like "the wrong way to do it".

The original code is this:

IPrototype p =  new prototype.PrototypeClient();

and I was sort of expecting it to work something like this.

string uri = GetMeMyURI();
IPrototype p =  new prototype.PrototypeClient(new URI(uri));

Upvotes: 0

Views: 1134

Answers (1)

sipsorcery
sipsorcery

Reputation: 30734

It's a little bit hard to tell what's going wrong without knowing what your PrototypeClient class is, is it a WCF proxy?

The basic mechanism for setting up a WCF client programatically is:

BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress(GetMeMyURI());
PrototypeClient yourProxy = new PrototypeClient(binding, address);

Edit:

To avoid having to know the server binding:

PrototypeClient yourProxy = new PrototypeClient();
yourProxy.Endpoint.Address = new EndpointAddress(GetMeMyURI(), null);

Upvotes: 1

Related Questions