views:

17

answers:

2

I made a client for accessing my WCF services in one project, and all classes that work with services inherit from this class:

public abstract class ServiceClient<TServiceClient> : IDisposable where TServiceClient : ICommunicationObject

This class is where I do stuff like disposing, logging when the client was called, etc. some common stuff which all service classes would normally do.

Everything worked fine, until I got the task to implement this on an old system. I got into a problem when I used this project (DLL) in an other project which cannot reference System.ServiceModel (since it's an old .NET 2.0 software that I still maintain, and upgrading it to 3.0 is out of the question). Here, if I omit where TServiceClient : ICommunicationObject then the project can build, but the ServiceClient cannot use, for example, client.Close() or client.State

So, is my only solution to drop the where statement, and rewrite the service classes?

+1  A: 

If you can't upgrade that project to 3.0, this (or a wrapper class) seems to be your only option.

Femaref
Hmm... I tried to wrap it a bit, making a simple static class with a static field that implement this class (inside that 3.0 project) but I'm still getting the same build error when i try to call any method use it in 2.0... I'm guessing if I were to implement all methods separately in static methods, it would work, but it kinda seems like a bad solution.
avance70
Well, in the end I just used `IDisposable`, instead of `ICommunicationObject` and rewritten some of the code -- though there is still a problem that I can't invoke the dispose directly (because it asks for 3.0 framework) but if i use the `using` statement, the client closes automatically.
avance70
A: 

What is stopping you upgrading? 3.0 is not really a new version of the framework, it is just some additional dll's. Your 2.0 code will run as before using the same .net libraries.

Shiraz Bhaiji
Unfortunately that 2.0 is not "my" code... it's a part of a huge software that manages international calls. Hence, I really don't have a say on how to code that, I just have to make adjustments for a small piece of that software.
avance70