通过REST服务传递Web服务对象

时间:2019-03-07 10:27:00

标签: c# json rest serialization json.net

我从WebService引用生成了类。它是自动生成的,因此我无法对其进行编辑。

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3190.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://url")]
public partial class ZamowienieReq
{

    private KalendarzReq kalendarzField;

    private NaglowekReq naglowekField;

    private TrasaWstepnaReq[] trasaWstepnaField;

    private int typZamowieniaField;

    private bool typZamowieniaFieldSpecified;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
    public KalendarzReq Kalendarz
    {
        get
        {
            return this.kalendarzField;
        }
        set
        {
            this.kalendarzField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
    public NaglowekReq Naglowek
    {
        get
        {
            return this.naglowekField;
        }
        set
        {
            this.naglowekField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute(IsNullable = true)]
    public TrasaWstepnaReq[] TrasaWstepna
    {
        get
        {
            return this.trasaWstepnaField;
        }
        set
        {
            this.trasaWstepnaField = value;
        }
    }

    /// <remarks/>
    public int TypZamowienia
    {
        get
        {
            return this.typZamowieniaField;
        }
        set
        {
            this.typZamowieniaField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool TypZamowieniaSpecified
    {
        get
        {
            return this.typZamowieniaFieldSpecified;
        }
        set
        {
            this.typZamowieniaFieldSpecified = value;
        }
    }
}

我想通过REST服务,属性为[FromBody]的post方法传递此类的对象,但是序列化程序(JsonConvert.SerializeObject)跳过诸如TypZamowienia之类的必填字段。

是否可以处理它,还是应该编写自己的DTO对象?

0 个答案:

没有答案