WCF DataContract VS DataContract接口 [英] WCF DataContract vs DataContract Interface

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

问题描述

新建WCF



从接口DataContact类继承



例如:



  [DataContract(命名空间= ...........)] 
公共类VesselSequence:IVesselSequence
{

[数据成员]
公众诠释AllocationId {搞定;组; }

[数据成员]
公共字符串ScenarioName {搞定;组; }
}

接口VesselSequence:IVesselSequence
{
公众诠释AllocationId {搞定;组; }
公共字符串ScenarioName {搞定;组; }
}


解决方案

您可以这样做:

  [DataContract(命名空间= ...........)] 
公共类VesselSequence: IVesselSequence
{
[数据成员]
公众诠释AllocationId {搞定;组; }
[数据成员]
公共字符串ScenarioName {搞定;组; }
}

接口IVesselSequence
{
INT AllocationId {搞定;组; }
串ScenarioName {搞定;组; }
}

您不能做到这一点,可悲的是:



 公共类VesselSequence:IVesselSequence 
{
公众诠释AllocationId {搞定;组; }
公共字符串ScenarioName {搞定;组; }
}

[DataContract(命名空间= ...........)]
接口IVesselSequence
{
[数据成员]
INT AllocationId {搞定;组; }
[数据成员]
串ScenarioName {搞定;组; }
}


New to WCF.

Can DataContact class inherit from Interface ?

eg:

[DataContract(Namespace = ...........)]
public class VesselSequence : IVesselSequence
{

    [DataMember]
    public int AllocationId { get; set; }

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

interface VesselSequence : IVesselSequence
{
    public int AllocationId { get; set; }
    public string ScenarioName { get; set; }
}

解决方案

You can do this:

[DataContract(Namespace = ...........)]
public class VesselSequence : IVesselSequence
{
    [DataMember]
    public int AllocationId { get; set; }
    [DataMember]
    public string ScenarioName { get; set; }
}

interface IVesselSequence
{
    int AllocationId { get; set; }
    string ScenarioName { get; set; }
}

You can't do this, sadly:

public class VesselSequence : IVesselSequence
{
    public int AllocationId { get; set; }
    public string ScenarioName { get; set; }
}

[DataContract(Namespace = ...........)]
interface IVesselSequence
{
    [DataMember]
    int AllocationId { get; set; }
    [DataMember]
    string ScenarioName { get; set; }
}

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

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