C# 在服务中使用通用基接口时,WCF代理不知道回调
我正在编写一些通用代码,可以在许多WCF服务中重复使用。我已经能够成功地使用泛型接口和基类,然后添加仅指定要使用的类型的派生接口和类:C# 在服务中使用通用基接口时,WCF代理不知道回调,c#,wcf,generics,C#,Wcf,Generics,我正在编写一些通用代码,可以在许多WCF服务中重复使用。我已经能够成功地使用泛型接口和基类,然后添加仅指定要使用的类型的派生接口和类: [ServiceContract] public interface IGenericContract<T> { [OperationContract] void DoSomething(T param); } [ServiceContract] public interface IService : IGenericContrac
[ServiceContract]
public interface IGenericContract<T>
{
[OperationContract]
void DoSomething(T param);
}
[ServiceContract]
public interface IService : IGenericContract<string> {}
// Re-usable generic base class
public class GenericService<T> : IGenericContract<T>
{
public void DoSomething(T param)
{
}
}
// Specific service implementation
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class Service : GenericService<string>, IService
{
}
这非常有效,直到我尝试使用相同的技术添加回调:
public interface IGenericCallback<T>
{
[OperationContract]
void DoSomethingOnClient(T param);
}
public interface ICallback : IGenericCallback<string>
{
}
// Add CallbackContract type to service
[ServiceContract(CallbackContract = typeof(ICallback))]
public interface IService : IGenericContract<string> { }
生成的代理不知道有关ICallback的任何信息。这是为什么?有办法解决吗?您是将您的服务注册为GenericService,还是注册为service?我将服务类实例托管为WCF服务
public interface IGenericCallback<T>
{
[OperationContract]
void DoSomethingOnClient(T param);
}
public interface ICallback : IGenericCallback<string>
{
}
// Add CallbackContract type to service
[ServiceContract(CallbackContract = typeof(ICallback))]
public interface IService : IGenericContract<string> { }