Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Service method - cannot be serialized because it does not have a parameterless constructor

I have added a web ref to my .net project which contains the methods for a 3rd party service.

When I try to call one of the methods its expecting an OrderIdentifier object to be passed but its giving me the error:

InvalidOperationException: <>f__AnonymousType0`3[System.DateTime,ETS_OpenAccessNew.ETS.DateRange,ETS_OpenAccessNew.ETS.AuctionIdentification] cannot be serialized because it does not have a parameterless constructor.

My code is as follows:

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

The classes being referenced are as follows:

[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]));
    }

Any ideas on what I'm doing wrong here would be much appreciated

Update - I have now included the parameterless contructor to the AuctionIdentification class but still getting the same error

like image 339
Gavin Crawley Avatar asked Aug 09 '18 12:08

Gavin Crawley


1 Answers

The exception message is telling you that you are trying to serialize anonymous type containing DateTime, DateRange and AuctionIdentification properties, and anonymous types indeed have no parameterless constructors (they are immutable, so their members are initialized via constructor parameters).

The problematic anonymous type is created and assigned to items variable here:

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

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

According to the Items property definition

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

it's an array of objects, where the actual type of the each object could be one of the 3 types described - DateTime, DateRange and AuctionIdentification.

Kind of strange design, but that's the fault of the 3rd party service, not yours. The proper initialization in your case (which also should fix the exception in question) should be to populate the array directly:

oi.Items = new object[] // <--
{
    DateTime.Today.AddDays(-1), // deliveryDay
    dr, // deliveryDays
    Ai // AuctionIdentification
};
like image 55
Ivan Stoev Avatar answered Sep 22 '22 14:09

Ivan Stoev