4

戻り値の型として複合型を返す関数を公開する 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 があることを知っていたので、データ コントラクトを使用するのはかなり新しいことを付け加えておく必要があります。

4

1 に答える 1

4

はい、 sDataContractsで構成できますDataContract。WCF は、それらを適切にシリアル化する方法を認識します。

于 2012-08-16T15:04:08.690 に答える