我正在试验 WCF 服务,遇到了传递接口(interface)的问题。
这个有效:
[ServiceContract]
public interface IHomeService
{
[OperationContract]
string GetString();
}
但这不是:
[ServiceContract]
public interface IHomeService
{
[OperationContract]
IDevice GetInterface();
}
当我尝试编译客户端时,它在 GetInterface 方法上失败了。我收到一个异常,指出它无法将 Object 转换为 IDevice。
在客户端,IHomeService 类使用字符串作为返回类型正确地实现了 GetString,但 GetInterface 的返回类型为对象。为什么不是 IDevice?
最佳答案
您需要告诉 WCF 序列化程序使用哪个类来序列化接口(interface)
[ServiceKnownType(typeof(ConcreteDeviceType)]
关于c# - 在 WCF 服务中传递接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/310160/