Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在服务中使用通用基接口时,WCF代理不知道回调_C#_Wcf_Generics - Fatal编程技术网

C# 在服务中使用通用基接口时,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

我正在编写一些通用代码,可以在许多WCF服务中重复使用。我已经能够成功地使用泛型接口和基类,然后添加仅指定要使用的类型的派生接口和类:

[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> { }