I have an application where client and server share types, and interoperability is not one of our concerns. I am planning to have a single repository for all web enabled objects, and i was thinking of a generic interface for my exposed service.
something like T GetObject(int id)
but wcf doesnt like it since its trying to expose its schema (which i dont really care about)
is it possible to do such a thing with WCF ?, i can use any type of binding doesnt have to be httpbinding or wsbinding…
I suppose this is possible, though I’m not sure you’d want this. I’d take the following approach (untested, not sure if it works). First create the following project structure in your solution:
ServiceInterfacesServiceImplementations(referencesServiceInterfacesandModelClasses)ModelClassesHost(referencesServiceInterfacesandServiceImplementations)Client(referencesServiceInterfacesandModelClasses)In
ServiceInterfacesyou have an interface like this (I skipped the namespaces, etc to make the example shorter):In
ServiceImplementationsyou have a class that implementsIMyService<T>:In
Hostyou have the correct configuration for your service in anApp.config(orWeb.config) file and the following code to host your service (given that it is a stand-alone app):And finally in
Clientyou use aChannelFactory<TChannel>class to define a proxy:Again, I’m not sure if this works. The trick is to share your service interfaces (in
ServiceInterfaces) and domain model objects (inModelClasses) between the host and the client. In my example I use a string to return from the service method but it could be any data contract type from theModelClassesproject.