第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Web 服務(wù)方法 - 無(wú)法序列化,因?yàn)樗鼪](méi)有無(wú)參數(shù)構(gòu)造函數(shù)

Web 服務(wù)方法 - 無(wú)法序列化,因?yàn)樗鼪](méi)有無(wú)參數(shù)構(gòu)造函數(shù)

C#
尚方寶劍之說(shuō) 2021-11-21 16:08:57
我在我的 .net 項(xiàng)目中添加了一個(gè) web 引用,其中包含 3rd 方服務(wù)的方法。當(dāng)我嘗試調(diào)用其中一種方法時(shí),它期望傳遞一個(gè) OrderIdentifier 對(duì)象,但它給了我錯(cuò)誤:InvalidOperationException: <>f__AnonymousType0`3[System.DateTime,ETS_OpenAccessNew.ETS.DateRange,ETS_OpenAccessNew.ETS.AuctionIdentification] 無(wú)法序列化,因?yàn)樗鼪](méi)有無(wú)參數(shù)構(gòu)造函數(shù)。我的代碼如下:        OrderIdentifier oi = new OrderIdentifier        {            area = testArea,            portfolio = testPortfolio        };        DateRange dr = new DateRange { from = DateTime.Today.AddDays(-7), to = DateTime.Today };        var Ai = new AuctionIdentification        {            Item = DateTime.Today.AddDays(-1),            ItemElementName = ItemChoiceType1.AuctionDate,            name = "test",            duration = AuctionIdentificationDuration.Item30min,            durationSpecified = true        };        object items = new        {            deliveryDay = DateTime.Today.AddDays(-1),            deliveryDays = dr,            AuctionIdentification = Ai        };         oi.Items = new object[1] { items };        var orders = oa.RetrieveOrders(oi);任何關(guān)于我在這里做錯(cuò)的想法將不勝感激更新 - 我現(xiàn)在已經(jīng)將無(wú)參數(shù)構(gòu)造函數(shù)包含在 AuctionIdentification 類中,但仍然出現(xiàn)相同的錯(cuò)誤
查看完整描述

2 回答

?
桃花長(zhǎng)相依

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊

異常的消息告訴你,你正在試圖序列匿名類型包含DateTime,DateRange以及AuctionIdentification性能和匿名類型的確沒(méi)有參數(shù)構(gòu)造函數(shù)(它們是不變的,所以他們的成員是通過(guò)構(gòu)造函數(shù)的參數(shù)初始化)。


有問(wèn)題的匿名類型在items此處創(chuàng)建并分配給變量:


object items = new // <--

{

    deliveryDay = DateTime.Today.AddDays(-1),

    deliveryDays = dr,

    AuctionIdentification = Ai

};


oi.Items = new object[1] { items };

根據(jù)Items屬性定義


[System.Xml.Serialization.XmlElementAttribute("AuctionIdentification", typeof(AuctionIdentification))]

[System.Xml.Serialization.XmlElementAttribute("deliveryDay", typeof(System.DateTime), DataType="date")]

[System.Xml.Serialization.XmlElementAttribute("deliveryDays", typeof(DateRange))]

public object[] Items {

    get {

        return this.itemsField;

    }

    set {

        this.itemsField = value;

    }

}

它的陣列objects,其中每個(gè)的實(shí)際類型object可以是所描述的3種類型中的一個(gè)- DateTime,DateRange和AuctionIdentification。


有點(diǎn)奇怪的設(shè)計(jì),但這是 3rd 方服務(wù)的錯(cuò),而不是你的錯(cuò)。在您的情況下正確的初始化(也應(yīng)該修復(fù)有問(wèn)題的異常)應(yīng)該是直接填充數(shù)組:


oi.Items = new object[] // <--

{

    DateTime.Today.AddDays(-1), // deliveryDay

    dr, // deliveryDays

    Ai // AuctionIdentification

};


查看完整回答
反對(duì) 回復(fù) 2021-11-21
?
斯蒂芬大帝

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

問(wèn)題出在這一行:


 DateRange dr = new DateRange { from = DateTime.Today.AddDays(-7), to = DateTime.Today };

您正在嘗試創(chuàng)建一個(gè)新實(shí)例,DateRange()但它不接受您的初始化,說(shuō)明您無(wú)法初始化該類,因?yàn)樗鼪](méi)有無(wú)參數(shù)構(gòu)造函數(shù),因?yàn)槟鷽](méi)有提供任何構(gòu)造函數(shù)。


這個(gè)類的一個(gè)很好的例子是:


DateRange range = new DateRange(fromDate, toDate, CultureInfo);


或者:


return new DateRange 

{

    from = DateTime.Today.AddDays(-7),

    to = DateTime.Today

};


查看完整回答
反對(duì) 回復(fù) 2021-11-21
  • 2 回答
  • 0 關(guān)注
  • 531 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)