tags:

views:

175

answers:

1

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));
+1  A: 

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);
sipwiz
Tried that, and it started yelling about incorrect modes of some kind relating to the BasicHttpBinding. *Come on WCF! Give me a darn default object already!*
BCS
Work around that works for me http://davidsandor.com/blogs/tipsandtricks/archive/2008/08/03/
BCS