I have a project that communicates with a WCF service to access data. Sometimes the server is local and then it uses sql stored procedures to query the database directly.
To explain, suppose I have the following method:
Asset GetAsset(int AssetID);
This method is either exposed by the WCF service or used locally when querying the database directly. The problem I have is that the Asset object for the exposed method of the WCF service is different to the local method. ie
Exposed service method is:
WcfService.Asset GetAsset(int AssetID);
Direct DB query method is:
LocalNamespace.Asset GetAsset(int AssetID);
While I can, I don’t want to make the Direct DB query method use the WcfService Asset object since I want to be able to remove the WcfService if need be. Ideally I want to bundle the common objects/interfaces in a separate assembly that I can use both locally and on the service.
Do I have any a choice though? Maybe I don’t know enough about the Referenced Assemblies option, although it is on.
You can definitely do that, it’s one of the great strengths of WCF. Create a separate assembly containing your
[DataContract]classes,[ServiceContract]interfaces, and nothing else. You can then use it however you like, in a WCF service, WCF client, or outside WCF altogether. Use the Referenced Assemblies option when adding a service reference to ensure that your contract assembly gets used.You can go one better than that. Move your service contract implementation classes into another separate assembly. You can then call them directly in-process without going via a service call. This reduces your WCF service project to a collection of
.svcfiles and aweb.config.