2011-03-30 56 views
3
public class _Base_Client<T> : System.ServiceModel.ClientBase<T> 

它抱怨The type 'T' must be a reference type in order to use it as parameter 'TChannel'继承通用类T必须是引用类型

T是一个接口的引用。

这是我希望的行更改为使用新的基类

public class EchoServiceClient : 
    System.ServiceModel.ClientBase<IEchoService>, IEchoService 

我怎样才能解决这个问题?谢谢

回答

10

变化:

public class _Base_Client<T> : System.ServiceModel.ClientBase<T> 

到:

public class _Base_Client<T> : System.ServiceModel.ClientBase<T> where T : class 

作为约束在它的基类(ClientBase)定义在你的类的约束必须至少为严格。要晓得,这里是ClientBase声明:

public abstract class ClientBase<TChannel> : ICommunicationObject, 
    IDisposable where TChannel : class 

通知的class约束。

+0

完美,谢谢。我现在在对象查看器中看到:类限制。感谢您也指出了这一点。 – 2011-03-30 23:02:06

0

你不能使用那里的接口。你需要一个具体的实现IEchoService

相关问题