我在.net项目中添加了一个Web引用,其中包含用于第三方服务的方法。
当我尝试调用其中一种方法时,它希望传递一个OrderIdentifier对象,但它给我错误:
InvalidOperationException:<> f__AnonymousType0`3 [System.DateTime,ETS_OpenAccessNew.ETS.DateRange,ETS_OpenAccessNew.ETS.AuctionIdentification]无法序列化,因为它没有无参数构造函数。 < / strong>
我的代码如下:
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类中,但是仍然出现相同的错误
答案 0 :(得分:7)
该异常消息告诉您,您正在尝试序列化包含DateTime
,DateRange
和AuctionIdentification
属性的匿名类型,而匿名类型的确没有无参数构造函数(它们是不可变的,因此它们的成员通过构造函数参数进行初始化)。
在这里创建有问题的匿名类型并将其分配给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种类型之一-DateTime
,DateRange
和{{1 }}。
那种奇怪的设计,但这是第三方服务的错,而不是您的错。在您的情况下,正确的初始化(这也应该解决相关异常)应该是直接填充数组:
AuctionIdentification
答案 1 :(得分:0)
问题出在这一行:
DateRange dr = new DateRange { from = DateTime.Today.AddDays(-7), to = DateTime.Today };
您正在尝试创建DateRange()
的新实例,但它不接受您的初始化,并指出您无法初始化该类,因为该类没有提供较少的参数构造函数,因为您未提供任何构造函数。
此类的一个很好的例子是:
DateRange range = new DateRange(fromDate, toDate, CultureInfo);
如果您想通过匿名类型初始化类,请使用以下命令:
或:
return new DateRange
{
from = DateTime.Today.AddDays(-7),
to = DateTime.Today
};