tags:

views:

520

answers:

2

I know I can do something like the following code to dynamically create a client endpoint connection in WCF:

BasicHttpBinding basic = 
    new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); 

basic.Security.Transport.ClientCredentialType = 
    HttpClientCredentialType.Ntlm; 

EndpointAddress serviceAddress = 
    new EndpointAddress("http://whatever/service.svc"); 

YourServiceClient m_client = new YourServiceClient(basic, serviceAddress);

The problem is that in this case I need to know what 'YourServiceClient' is. What I want to be able to do is be getting the type 'YourServiceClient' from a DB, where its stored as an object. Does anyone know how I would go about doing something like this? Where I have the value of 'YourServiceClient' in an object I've retrieved from the DB?

A: 

Nicholas Allen has covered something (I think) like this in his blog, start with part 1

There is also, IIRC, an ability to just receive the raw XML message, which you could then process yourself rather than working with a type specific proxy.

Richard
A: 

You aren't going to be able to do this. Basically, you are asking to get an unknown at runtime, but while binding to a known type at compile time. This simply cannot be done if the services that you are trying to access have some sort of shared interface.

If they do have the same interface (meaning, the same set of methods, etc, etc) then you can use the example here to create your own channel factory at runtime, and get a proxy that implements the interface for the service:

http://msdn.microsoft.com/en-us/library/ms734681.aspx

casperOne