草庐IT

c# - Web 服务方法 - 无法序列化,因为它没有无参数构造函数

coder 2024-06-25 原文

我已将 Web 引用添加到我的 .net 项目,其中包含第 3 方服务的方法。

当我尝试调用其中一种方法时,它期望传递 OrderIdentifier 对象,但它给我错误:

InvalidOperationException: <>f__AnonymousType0`3[System.DateTime,ETS_OpenAccessNew.ETS.DateRange,ETS_OpenAccessNew.ETS.AuctionIdentification] 无法序列化,因为它没有无参数构造函数。

我的代码如下:

        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);

被引用的类如下:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3130.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:openaccess")]
public partial class OrderIdentifier : IdentifiedOrder {
}

[System.Xml.Serialization.XmlIncludeAttribute(typeof(OrderIdentifier))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Order))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ComplexOrderIdentification))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3130.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:openaccess")]
public partial class IdentifiedOrder : AbstractOrderObject {

    private string areaField;

    private string portfolioField;

    private object[] itemsField;

    /// <remarks/>
    public string area {
        get {
            return this.areaField;
        }
        set {
            this.areaField = value;
        }
    }

    /// <remarks/>
    public string portfolio {
        get {
            return this.portfolioField;
        }
        set {
            this.portfolioField = value;
        }
    }

    /// <remarks/>
    [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;
        }
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Curve))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(IdentifiedOrder))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(OrderIdentifier))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Order))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ComplexOrderIdentification))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3130.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:openaccess")]
public partial class AbstractOrderObject : OpenAccessAbstractObject {
}

/// <remarks/>
[System.Xml.Serialization.XmlIncludeAttribute(typeof(MarketResultIdentifier))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Broadcast))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockOrderBatch))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AuctionInformationQuery))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AuctionDateTime))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AsynchronousResponseHeader))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AreaPortfolioInformationQuery))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(MessageAbstractObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Messages))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(MessageIdentifier))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ClientMessage))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(MarketResult))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(HourlyOrderAbstractObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(HourlyOrderIdentification))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(HourlyPeriod))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(HourlyOrder))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CurvePoint))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AbstractOrderObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Curve))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(IdentifiedOrder))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(OrderIdentifier))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Order))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ComplexOrderIdentification))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ComplexOrder))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AuctionInformation))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AreaAuctionIdentification))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AreaPortfolioInformation))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AreaInformation))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AsynchronousNotification))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ExclusiveGroupIndexToIdMapping))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockIndexToIdMapping))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AuctionIdentification))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockOrderAbstractObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockOrderIdentifier))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockOrder))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockPeriod))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(SmartBlockOrderAbstractObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(SmartBlockOrder))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockOrderForBatch))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ErrorObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Acknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(UserLogoutAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(SetNewPasswordAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(SetMessagesAsReadAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveTradeableAreaSetsAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveSmartBlockOrdersAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveOrdersAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveMessagesAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveMarketResultAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveHourlyOrdersAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveComplexOrdersAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveBlockOrdersAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveAuctionInformationAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveAreaPortfolioInformationAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveAreaInformationAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ReportRelayServerErrorResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ReportRelayErrorResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RemoveReverseConnectionResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RegisterUserOnServerResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RegisterForAsyncEventsResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ProcessAsynchronousNotificationResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(LogoutAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(GetNotificationsResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EstablishSessionResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EstablishReverseConnectionResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EnterHourlyOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EnterOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EnterComplexOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EnterBlockOrderBatchAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EnterBlockOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(DeRegisterUserOnServerResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelHourlyOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelComplexOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelBlockOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BroadcastAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AcceptNotificationResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrievePortfoliosAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveViewablePortfoliosAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveTradablePortfoliosAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveBlocksAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveGroupAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveExclusiveGroupAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveAreasAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveViewableAreasAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveTradableAreasAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelBlockAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelGroupAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelExclusiveGroupAcknowledgement))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3130.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:openaccess")]
public partial class OpenAccessAbstractObject : DomainObject {
    public OpenAccessAbstractObject() { }
}

[System.Xml.Serialization.XmlIncludeAttribute(typeof(ResponseLimitationHeader))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(OpenAccessAbstractObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(MarketResultIdentifier))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Broadcast))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockOrderBatch))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AuctionInformationQuery))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AuctionDateTime))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AsynchronousResponseHeader))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AreaPortfolioInformationQuery))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(MessageAbstractObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Messages))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(MessageIdentifier))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ClientMessage))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(MarketResult))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(HourlyOrderAbstractObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(HourlyOrderIdentification))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(HourlyPeriod))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(HourlyOrder))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CurvePoint))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AbstractOrderObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Curve))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(IdentifiedOrder))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(OrderIdentifier))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Order))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ComplexOrderIdentification))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ComplexOrder))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AuctionInformation))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AreaAuctionIdentification))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AreaPortfolioInformation))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AreaInformation))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AsynchronousNotification))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ExclusiveGroupIndexToIdMapping))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockIndexToIdMapping))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AuctionIdentification))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockOrderAbstractObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockOrderIdentifier))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockOrder))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockPeriod))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(SmartBlockOrderAbstractObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(SmartBlockOrder))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BlockOrderForBatch))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ErrorObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Acknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(UserLogoutAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(SetNewPasswordAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(SetMessagesAsReadAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveTradeableAreaSetsAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveSmartBlockOrdersAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveOrdersAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveMessagesAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveMarketResultAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveHourlyOrdersAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveComplexOrdersAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveBlockOrdersAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveAuctionInformationAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveAreaPortfolioInformationAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveAreaInformationAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ReportRelayServerErrorResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ReportRelayErrorResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RemoveReverseConnectionResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RegisterUserOnServerResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RegisterForAsyncEventsResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ProcessAsynchronousNotificationResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(LogoutAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(GetNotificationsResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EstablishSessionResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EstablishReverseConnectionResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EnterHourlyOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EnterOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EnterComplexOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EnterBlockOrderBatchAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EnterBlockOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(DeRegisterUserOnServerResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelHourlyOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelComplexOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelBlockOrderAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BroadcastAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AcceptNotificationResponse))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrievePortfoliosAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveViewablePortfoliosAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveTradablePortfoliosAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveBlocksAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveGroupAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveExclusiveGroupAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveAreasAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveViewableAreasAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RetrieveTradableAreasAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelBlockAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelGroupAcknowledgement))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CancelExclusiveGroupAcknowledgement))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3130.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:openaccess")]
public partial class DomainObject : System.Web.Services.Protocols.SoapHeader {
}    


[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3130.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:openaccess")]
public partial class AuctionIdentification : OpenAccessAbstractObject {

    public AuctionIdentification(){}

    private System.DateTime itemField;

    private ItemChoiceType1 itemElementNameField;

    private string nameField;

    private AuctionIdentificationDuration durationField;

    private bool durationFieldSpecified;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("AuctionDate", typeof(System.DateTime), DataType="date")]
    [System.Xml.Serialization.XmlElementAttribute("UTCDateTime", typeof(System.DateTime))]
    [System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
    public System.DateTime Item {
        get {
            return this.itemField;
        }
        set {
            this.itemField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public ItemChoiceType1 ItemElementName {
        get {
            return this.itemElementNameField;
        }
        set {
            this.itemElementNameField = value;
        }
    }

    /// <remarks/>
    public string name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
        }
    }

    /// <remarks/>
    public AuctionIdentificationDuration duration {
        get {
            return this.durationField;
        }
        set {
            this.durationField = value;
        }
    }

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


//Retrieve Orders
[System.Web.Services.Protocols.SoapHeaderAttribute("SessionTokenValue")]
    [System.Web.Services.Protocols.SoapHeaderAttribute("ResponseLimitationHeaderValue", Direction=System.Web.Services.Protocols.SoapHeaderDirection.InOut)]
    [System.Web.Services.Protocols.SoapRpcMethodAttribute("RetrieveOrders", RequestNamespace="urn:openaccess", ResponseNamespace="urn:openaccess", Use=System.Web.Services.Description.SoapBindingUse.Literal)]
    public RetrieveOrdersAcknowledgement RetrieveOrders(OrderIdentifier OrderIdentifier) {
        object[] results = this.Invoke("RetrieveOrders", new object[] {
                    OrderIdentifier});
        return ((RetrieveOrdersAcknowledgement)(results[0]));
    }

任何关于我在这里做错的想法都将不胜感激

更新 - 我现在已将无参数构造函数包含到 AuctionIdentification 类中,但仍然出现相同的错误

最佳答案

异常消息告诉您您正在尝试序列化包含 DateTimeDateRangeAuctionIdentification匿名类型> 属性和匿名类型确实没有无参数构造函数(它们是不可变的,因此它们的成员是通过构造函数参数初始化的)。

有问题的匿名类型在此处创建并分配给 items 变量:

object items = new // <--
{
    deliveryDay = DateTime.Today.AddDays(-1),
    deliveryDays = dr,
    AuctionIdentification = Ai
};

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

根据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;
    }
}

它是一个 object 数组,其中每个 object 的实际类型可能是描述的 3 种类型之一 - DateTimeDateRangeAuctionIdentification

有点奇怪的设计,但那是第 3 方服务的错,而不是你的错。在你的情况下正确的初始化(这也应该修复有问题的异常)应该是直接填充数组:

oi.Items = new object[] // <--
{
    DateTime.Today.AddDays(-1), // deliveryDay
    dr, // deliveryDays
    Ai // AuctionIdentification
};

关于c# - Web 服务方法 - 无法序列化,因为它没有无参数构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51766957/

有关c# - Web 服务方法 - 无法序列化,因为它没有无参数构造函数的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  3. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  4. ruby - 使用 ruby​​ 和 savon 的 SOAP 服务 - 2

    我正在尝试使用ruby​​和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我

  5. ruby - Facter::Util::Uptime:Module 的未定义方法 get_uptime (NoMethodError) - 2

    我正在尝试设置一个puppet节点,但ruby​​gems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由ruby​​gems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby

  6. ruby - 具有身份验证的私有(private) Ruby Gem 服务器 - 2

    我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..

  7. Ruby 方法() 方法 - 2

    我想了解Ruby方法methods()是如何工作的。我尝试使用“ruby方法”在Google上搜索,但这不是我需要的。我也看过ruby​​-doc.org,但我没有找到这种方法。你能详细解释一下它是如何工作的或者给我一个链接吗?更新我用methods()方法做了实验,得到了这样的结果:'labrat'代码classFirstdeffirst_instance_mymethodenddefself.first_class_mymethodendendclassSecond使用类#returnsavailablemethodslistforclassandancestorsputsSeco

  8. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  9. ruby - Highline 询问方法不会使用同一行 - 2

    设置:狂欢ruby1.9.2高线(1.6.13)描述:我已经相当习惯在其他一些项目中使用highline,但已经有几个月没有使用它了。现在,在Ruby1.9.2上全新安装时,它似乎不允许在同一行回答提示。所以以前我会看到类似的东西:require"highline/import"ask"Whatisyourfavoritecolor?"并得到:Whatisyourfavoritecolor?|现在我看到类似的东西:Whatisyourfavoritecolor?|竖线(|)符号是我的终端光标。知道为什么会发生这种变化吗? 最佳答案

  10. ruby - 主要 :Object when running build from sublime 的未定义方法 `require_relative' - 2

    我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby​​1.9+ 关于ruby-主要:Objectwhenrun

随机推荐