views:

1683

answers:

2

We currently have developed an application using WCF. Our clients make connections to different WCF servicehosts located on the server, and the servicehosts return the data from the DB that the clients need. Standard model. However, this current design has all of our WCF data in app.config files both on the client side as well as the servicehost side. We want to make this more dynamic, and have moved all of the data, including the endpoints, the contracts, and the bindings, into the DB.

Now the question is how do we retrieve this data, and access it properly. We've got the design working where we have one defined endpoint in a config file, and using that endpoint, we can make a call to it to get the rest of the endpoint information that we need (i.e. all of the bindings, contracts and different endpoints that it used to have defined in its app.config). This is the case on both the client side as well as the servicehost side.

The issue that I'm now struggling with is how do I code against these dynamic endpoints? When the client makes a call to the servicehost, it not only is making simple calls to the servicehost, but retrieving and passing back objects for the servicehost to process as needed. For example, on form load we may retrieve the object with all of the currently defined settings from the DB, and then the user does whatever on the fornm, and we then pass back the updated object to the servicehost. We can do that now because in Visual Studio 2008 we've added all of the service references, which has auto-generated the methods and objects that can be called and retrieved from the servicehosts. If we go to a dynamic endpoint connection, how do we get this data during the development phase?

I've developed a similar application in the past in .NET 2.0 using .NET remoting, where we were passing the object back and forth, and the client and server both used the same object definition class to know about the object. I'm not sure how we would go about doing this with WCF.

A: 

You don't have to rely on app.config file to configure the service, you can configure the service at runtime e.g. get for for bindings, endpoints or behaviors from database to configure servicehost object.

However, the service, data or message contracts should be coded in the solution or web referenced otherwise it'd degrade the performance by heavily using reflection and lots of complexity to achieve the whole dynamic features.

In your scenario, I guess it can be done by some other way, e.g. process generic message. Implement the logic for processing any message data in the request. Hopefully, you can get more ideas by reading the articles about how to process 'any' message from client and server.

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

codemeit
A: 

Define your binding and then use it to instantiate the client.

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);
This works, if I know what type 'YourServiceClient' is. The problem I am running into is when the type is being returned back from a DB, and not known at the time of instantiation.
Noah