WCF:如何构建DataContracts的类型中的类型(WCF: How to construct

2019-09-21 06:31发布

我有一个公开返回一个复杂类型作为它的返回类型的函数的WCF服务。 反过来,这种响应类型包含由我定义的另一个复杂的对象。 我期待在创造我的WCF数据契约,我想知道这是怎么应该做。 目前,我有这个(些属性,便于阅读删除):

功能

///<summary>
/// Interface to describe a cluster query WCF service.
///</summary>
[ServiceContract]
public interface IClusterQueryWcfService
{
    /// <summary>
    /// A method to retrieve the name of the necessary cluster table for a given zoom level, feature type and user type. 
    /// </summary>
    /// <param name="zoom">Integer value representing zoom level</param>
    /// <param name="featureType">The feature type string</param>
    /// <param name="user">User name</param>
    /// <returns>RwolTableType made up of table name and table type.(See documentation)</returns>
    [OperationContract]
    TableTypeResponse GetClusterTableForZoom(int zoom, string featureType, string user);

响应类型

/// <summary>
/// The data contract for a TableTypeResponse object
/// </summary>
[DataContract]
public class TableTypeResponse
{
    /// <summary>
    /// Property to manipulate the date and time of the method call.
    /// </summary>
    [DataMember]
    public string DateTimeOfCall
    {
        get;
        set;
    }

    /// <summary>
    /// Property to get/set the StandardResponse type object included with a TableTypeResponse instance.
    /// </summary>
    [DataMember]
    public StandardResponseType StandardResponse
    {
        get;
        set;
    }
}

嵌套类型

/// <summary>
/// Data contract for a StandardResponseType object
/// </summary>
[DataContract]
public class StandardResponseType
{
    /// <summary>
    /// Property to manipulate the date and time of the method call.
    /// </summary>
    [DataMember]
    public string DateTimeOfCall
    {
        get;
        set;
    }

    /// <summary>
    /// Property to allow get and set of a message to provide more information to the user.
    /// </summary>
    [DataMember]
    public string Message
    {
        get;
        set;
    }
}

此代码足以确保调用客户端知道最初的反应式中举行的标准响应类型的结构? 我的意思是会为嵌套类型的数据实际上合同被观察?

我要补充我是相当新的使用数据作为合同之前,我知道我已经.NET两侧。

Answer 1:

是的,你可以有DataContracts组成的DataContract秒。 WCF会知道如何正确序列化。



文章来源: WCF: How to construct DataContracts for a type within a type