.Net Web服务无法在JSON中处理复杂对象

时间:2015-08-27 08:30:43

标签: c# json wcf rest serialization

在这里,您可以找到我的网络服务内容:

[ServiceContract]
public interface IProcessing
{
    [OperationContract]
    [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "person/{id}")]
    Person GetPerson(string id);
}

我有两个型号,人物和图片。 当我尝试用JSON中的网络服务获取图片时,一切都很好,WS返回的结果是正确的。

但是当我尝试发送Person Object时,这是不一样的.beacuse Person包含Picture。

在这里您可以找到我的模型属性:

 Person : 
{
    using System;
    using System.Runtime.Serialization;

    /// <summary>
    /// Class which define the object Person.
    /// </summary>
    [DataContract]
    public class Person
    {
        #region Constructor

        /// <summary>
        /// Constructor
        /// </summary>
        public Person()
        {

        }

图片:

/// <summary>
    /// Class which define the object Team.
    /// </summary>
    [DataContract]
    public class Picture
    {
        #region Constructor

        /// <summary>
        /// Constructor
        /// </summary>
        public Picture()
        {

        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the id of the picture
        /// </summary>
        [DataMember]
        public int ID { get; set; }

        /// <summary>
        /// Gets or sets the url of the picture
        /// </summary>
        [DataMember]
        public string URL { get; set; }

        /// <summary>
        /// Gets or sets the color code of the picture
        /// </summary>
        [DataMember]
        public string ColorCode { get; set; }

        #endregion

    }
}

0 个答案:

没有答案