客户端合同中的接口 [英] Interfaces in contract on client

查看:27
本文介绍了客户端合同中的接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的合同:

[DataContract]
[KnownType(typeof(Person))]
public class Gadget
{
    [DataMember]
    public int Id { get; set; }

    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public IPerson Person { get; set; }
}

它代表一个属于一个人的小工具.我只是想出了这个简单的例子,它是否有意义并不重要.

It represents a gadget that belongs to a person. I just came up with this simple example, it's not important whether it makes sense or not.

因此,我没有返回 Person 类,而是返回 IPerson 接口.现在客户端不能再生成强类型对象,但会生成这个:

So, instead of returning the Person class, I return the IPerson interface. Now the client can no longer generate a strong typed object, but will generate this:

public object Person { get; set; }

现在我的问题是:是否可以让客户端也生成 IPerson 接口?它应该有足够的信息,因为它只能实例化Person(仅已知类型).

Now my question is: is it possible to let the client also generate the IPerson interface? It should have enough information, because it can only instantiate Person (only known type).

推荐答案

不会通过添加服务引用来传输接口.这些接口仅存在于 .NET 中,但您的服务应该是可互操作的.

Interfaces will not be transfered by adding a service reference. These interfaces only exist in .NET, but your service is suppossed to be interoperable.

就您的 WSDL 而言,可能无法区分 Person 和 IPerson.

As far as your WSDL is concerned there is likely to be no way to tell Person and IPerson apart.

如果您真的想使用该界面,则需要手动移动它.这意味着手动编辑生成的客户端代码.

If you really want to use that interface you will need to move it across manually. This means editing the generated client code by hand.

这篇关于客户端合同中的接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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