传递接口在WCF服务? [英] Passing Interface in a WCF Service?

查看:191
本文介绍了传递接口在WCF服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用WCF服务,以及所遇到的一个问题,经过接口。

I'm experimenting with WCF Services, and have come across a problem with passing Interfaces.

本作品:

[ServiceContract]
public interface IHomeService
{
    [OperationContract]
    string GetString();
}

但这并不:

[ServiceContract]
public interface IHomeService
{
    [OperationContract]
    IDevice GetInterface();
}

当我尝试编译失败的GetInterface方法的客户端。我得到一个异常说,它不能转换为对象的iDevice。

When I try to compile the client it fails on the GetInterface method. I get an Exception saying that it can't convert Object to IDevice.

在客户方的IHomeService类正确实现的GetString一个字符串作为它的返回类型,但GetInterface具有对象的返回类型。为什么不是它的iDevice?

On the clientside the IHomeService class correctly implements GetString with a string as it's returntype, but the GetInterface has a returntype of object. Why isn't it IDevice?

推荐答案

您需要告诉WCF序列化哪一个类使用序列化接口

You need to tell the WCF serializer which class to use to serialize the interface

[ServiceKnownType(typeof(ConcreteDeviceType)]

这篇关于传递接口在WCF服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆