R – How to work with objects using Dynamic WCF

.net-3.5netwcfweb services

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.

Best Answer

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);
Related Topic