Я работаю со сгенерированным классом C#, используя System.Xml.Serialization.XmlSerializer для сериализации объекта в XML. Созданный класс включает перечисление ItemChoiceType и свойство ItemElementName, которое определяет, какой XML-элемент сериализовать. Вот соответствующая часть сгенерированного кода:
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.2.0-preview1.23462.5")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.opentravel.org/OTA/2003/05", IncludeInSchema=false)]
public enum ItemChoiceType
{
DepartureDateTime,
ArrivalDateTime,
ArrivalDates,
DepartureDates,
}
[System.Xml.Serialization.XmlElementAttribute(Order=1)]
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemChoiceType ItemElementName
{
get
{
return this.itemElementNameField;
}
set
{
this.itemElementNameField = value;
}
}
[System.Xml.Serialization.XmlElementAttribute("ArrivalDateTime", typeof(string), Order=0)]
[System.Xml.Serialization.XmlElementAttribute("ArrivalDates", typeof(TravelDateTimeTypeArrivalDates), Order=0)]
[System.Xml.Serialization.XmlElementAttribute("DepartureDateTime", typeof(string), Order=0)]
[System.Xml.Serialization.XmlElementAttribute("DepartureDates", typeof(TravelDateTimeTypeDepartureDates), Order=0)]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
public object Item
{
get
{
return this.itemField;
}
set
{
this.itemField = value;
}
}
< /code>
Это мой фактический метод для картирования значения для модели и конвертирования в XML. < /p>
public async Task bargainFinder(FlightSearchDTO model)
{
try
{
if (string.IsNullOrEmpty(model.DepartureDateString) == false)
{
model.DepartureDate = Convert.ToDateTime(model.DepartureDateString);
}
if (string.IsNullOrEmpty(model.ReturnDateString) == false)
{
model.ReturnDate = Convert.ToDateTime(model.ReturnDateString);
}
string endpoint = sabreSetting.SessionCreateEndPoint;
string ipcc = sabreSetting.IPCC;
string convId = sabreSetting.ConversationId;
string binarySecurityToken = @"Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/ACPCRTD!ICESMSLB\/CRT.LB!-2776506000596342904!1865259!0";
string seatClass = "";
SabreSessionDTO sessionDetail = await _sabreSessionService.GetSabreSessionById(model.SessionId);
if (sessionDetail == null || sessionDetail.ExpireOn < DateTime.Now || sessionDetail.IsExpired == true)
{
model.SessionId = await sessionCreate(sessionDetail.FlightSearchId ?? 0);
sessionDetail = await _sabreSessionService.GetSabreSessionById(model.SessionId);
}
binarySecurityToken = sessionDetail.SecurityToken;
convId = sessionDetail.ConversationId;
ipcc = sabreSetting.IPCC;
EndpointAddress url = new EndpointAddress(new Uri(endpoint));
Binding binding = new BasicHttpsBinding()
{
MaxReceivedMessageSize = Int32.MaxValue,
MaxBufferSize = Int32.MaxValue
};
BargainFinderMaxPortTypeClient bargainFinderMaxPortTypeClient = new BargainFinderMaxPortTypeClient(binding, u r l ) ; < b r / > < b r / > B a r g a i n F i n d e r M a x . M e s s a g e H e a d e r m e s s a g e H e a d e r = n e w B a r g a i n F i n d e r M a x . M e s s a g e H e a d e r ( ) < b r / > { < b r / > F r o m = n e w F r o m ( ) < b r / > { < b r / > P a r t y I d = n e w P a r t y I d [ ] < b r / > { < b r / > n e w P a r t y I d ( ) < b r / > { < b r / > V a l u e = i p c c < b r / > } < b r / > } < b r / > } , < b r / > T o = n e w T o ( ) < b r / > { < b r / > P a r t y I d = n e w P a r t y I d [ ] < b r / > { < b r / > n e w P a r t y I d ( ) < b r / > { < b r / > V a l u e = e n d p o i n t < b r / > } < b r / > } < b r / > } , < b r / > C o n v e r s a t i o n I d = c o n v I d , < b r / > C P A I d = i p c c , < b r / > S e r v i c e = n e w B a r g a i n F i n d e r M a x . S e r v i c e ( ) < b r / > { < b r / > V a l u e = & q u o t ; B a r g a i n F i n d e r M a x R Q & q u o t ; < b r / > } , < b r / > A c t i o n = & q u o t ; B a r g a i n F i n d e r M a x R Q & q u o t ; , < b r / > M e s s a g e D a t a = n e w M e s s a g e D a t a ( ) < b r / > { < b r / > M e s s a g e I d = & q u o t ; 2 0 2 5 0 1 1 9 - 1 2 1 4 5 4 1 7 1 - 7 5 1 8 . B A R G A I N F I N D E R M A X R S @ w e b s e r v i c e s . s a b r e . c o m & q u o t ; , < b r / > T i m e s t a m p = D a t e T i m e . U t c N o w . T o S t r i n g ( & q u o t ; y y y y - M M - d d T H H : m m : s s K & q u o t ; ) , < b r / > T i m e T o L i v e = D a t e T i m e . U t c N o w < b r / > } , < b r / > D e s c r i p t i o n = n e w D e s c r i p t i o n [ ] < b r / > { < b r / > n e w D e s c r i p t i o n < b r / > { < b r / > V a l u e = & q u o t ; B a r g a i n F i n d e r M a x S e r v i c e & q u o t ; < b r / > } < b r / > } < b r / > } ; < b r / > < b r / > B a r g a i n F i n d e r M a x . S e c u r i t y s e c u r i t y = n e w B a r g a i n F i n d e r M a x . S e curity()
{
BinarySecurityToken = binarySecurityToken
};
OTA_AirLowFareSearchRQ ota_AirLowFareSearchRQ = new OTA_AirLowFareSearchRQ();
ota_AirLowFareSearchRQ.Version = "6.9.0";
ota_AirLowFareSearchRQ.AvailableFlightsOnly = true;
//ota_AirLowFareSearchRQ.AvailableFlightsOnlySpecified = true;
ota_AirLowFareSearchRQ.ResponseType = "OTA";
ota_AirLowFareSearchRQ.Target = OTA_AirLowFareSearchRQTarget.Production;
ota_AirLowFareSearchRQ.POS = new POS_Type
{
Source = new SourceType[]
{
new SourceType
{
PseudoCityCode =ipcc,
RequestorID = new UniqueID_Type()
{
ID = "1",
Type = "1",
CompanyName = new CompanyNameType()
{
Code = "TN",
Value = "TN"
}
}
}
}
};
if (model.TripType == 1)
{
ota_AirLowFareSearchRQ.OriginDestinationInformation = new OTA_AirLowFareSearchRQOriginDestinationInformation[1];
ota_AirLowFareSearchRQ.OriginDestinationInformation[0] = new OTA_AirLowFareSearchRQOriginDestinationInformation()
{
RPH = "1",
ItemElementName = ItemChoiceType.DepartureDateTime,
Item = model.DepartureDate.Value.ToString("yyyy-MM-ddTHH:mm:ss"),
OriginLocation = new OriginDestinationInformationTypeOriginLocation()
{
LocationCode = model.DepartureFrom
},
DestinationLocation = new OriginDestinationInformationTypeDestinationLocation()
{
LocationCode = model.ArrivalTo
}
};
}
if (model.TripType == 2)
{
ota_AirLowFareSearchRQ.OriginDestinationInformation = new OTA_AirLowFareSearchRQOriginDestinationInformation[2];
ota_AirLowFareSearchRQ.OriginDestinationInformation[0] = new OTA_AirLowFareSearchRQOriginDestinationInformation()
{
RPH = "1",
ItemElementName = ItemChoiceType.DepartureDateTime,
Item = model.DepartureDate.Value.ToString("yyyy-MM-ddTHH:mm:ss"),
OriginLocation = new OriginDestinationInformationTypeOriginLocation()
{
LocationCode = model.DepartureFrom
},
DestinationLocation = new OriginDestinationInformationTypeDestinationLocation()
{
LocationCode = model.ArrivalTo
},
TPA_Extensions = new OTA_AirLowFareSearchRQOriginDestinationInformationTPA_Extensions
{
SegmentType = new ExchangeOriginDestinationInformationTypeSegmentType
{
Code = ExchangeOriginDestinationInformationTypeSegmentTypeCode.O
}
}
};
ota_AirLowFareSearchRQ.OriginDestinationInformation[1] = new OTA_AirLowFareSearchRQOriginDestinationInformation()
{
RPH = "2",
ItemElementName = ItemChoiceType.DepartureDateTime,
Item = model.ReturnDate.Value.ToString("yyyy-MM-ddTHH:mm:ss"),
OriginLocation = new OriginDestinationInformationTypeOriginLocation()
{
LocationCode = model.ArrivalTo
},
DestinationLocation = new OriginDestinationInformationTypeDestinationLocation()
{
LocationCode = model.DepartureFrom
},
TPA_Extensions = new OTA_AirLowFareSearchRQOriginDestinationInformationTPA_Extensions
{
SegmentType = new ExchangeOriginDestinationInformationTypeSegmentType
{
Code = ExchangeOriginDestinationInformationTypeSegmentTypeCode.O
}
}
};
}
if (model.TripType == 3 && model.MulticityItems != null && model.MulticityItems.Count > 0)
{
ota_AirLowFareSearchRQ.OriginDestinationInformation = new OTA_AirLowFareSearchRQOriginDestinationInformation[model.MulticityItems.Count];
int cityCount = 1;
foreach (var item in model.MulticityItems)
{
ota_AirLowFareSearchRQ.OriginDestinationInformation[cityCount - 1 ] = n e w O T A _ A i r L o w F a r e S e a r c h R Q O r i g i n D e s t i n a t i o n I n f o r m a t i o n ( ) < b r / > { < b r / > R P H = c i t y C o u n t . T o S t r i n g ( ) , < b r / > I t e m E l e m e n t N a m e = I t e m C h o i c e T y p e . D e p a r t u r e D a t e T i m e , < b r / > I t e m = C o n v e r t . T o D a t e T i m e ( i t e m . D e p a r t u r e D a t e S t r i n g ) . T o S t r i n g ( & q u o t ; y y y y - M M - d d T H H : m m : s s & q u o t ; ) , < b r / > O r i g i n L o c a t i o n = n e w O r i g i n D e s t i n a t i o n I n f o r m a t i o n T y p e O r i g i n L o c a t i o n ( ) < b r / > { < b r / > L o c a t i o n C ode = item.DepartureFrom
},
DestinationLocation = new OriginDestinationInformationTypeDestinationLocation()
{
LocationCode = item.ArrivalTo
},
TPA_Extensions = new OTA_AirLowFareSearchRQOriginDestinationInformationTPA_Extensions
{
SegmentType = new ExchangeOriginDestinationInformationTypeSegmentType
{
Code = ExchangeOriginDestinationInformationTypeSegmentTypeCode.O
}
}
};
cityCount++;
}
}
AirTripType tripTypeValue = new AirTripType();
if (model.TripType == 1)
{
tripTypeValue = AirTripType.OneWay;
}
if (model.TripType == 2)
{
tripTypeValue = AirTripType.Return;
}
if (model.TripType == 3)
{
tripTypeValue = AirTripType.OpenJaw;
}
if (model.SeatClass 0)
{
totalPassengerType++;
totalPassenger = model.TravellerAdult;
}
if (model.TravellerChildren > 0)
{
totalPassengerType++;
totalPassenger += model.TravellerChildren;
}
if (model.TravellerInfant > 0)
{
totalPassengerType++;
totalPassenger += model.TravellerInfant;
}
ota_AirLowFareSearchRQ.TravelerInfoSummary = new TravelerInfoSummaryType()
{
SeatsRequested = new[]
{
totalPassenger.ToString()
}
};
ota_AirLowFareSearchRQ.TravelerInfoSummary.AirTravelerAvail = new TravelerInformationType[] {
new TravelerInformationType()
};
ota_AirLowFareSearchRQ.TravelerInfoSummary.AirTravelerAvail[0].PassengerTypeQuantity = new PassengerInfoType[totalPassengerType];
int travelerType = 0;
if (model.TravellerAdult > 0)
{
ota_AirLowFareSearchRQ.TravelerInfoSummary.AirTravelerAvail[0].PassengerTypeQuantity[travelerType] = new PassengerInfoType()
{
Code = "ADT",
Quantity = model.TravellerAdult.ToString()
};
travelerType++;
};
if (model.TravellerChildren > 0)
{
ota_AirLowFareSearchRQ.TravelerInfoSummary.AirTravelerAvail[0].PassengerTypeQuantity[travelerType] = new PassengerInfoType()
{
Code = "CNN",
Quantity = model.TravellerChildren.ToString()
};
travelerType++;
};
if (model.TravellerInfant > 0)
{
ota_AirLowFareSearchRQ.TravelerInfoSummary.AirTravelerAvail[0].PassengerTypeQuantity[travelerType] = new PassengerInfoType()
{
Code = "INF",
Quantity = model.TravellerInfant.ToString()
};
travelerType++;
};
ota_AirLowFareSearchRQ.TPA_Extensions = new OTA_AirLowFareSearchRQTPA_Extensions()
{
IntelliSellTransaction = new TransactionType()
{
RequestType = new TransactionTypeRequestType()
{
Name = sabreSetting.NumberOfResult + "ITINS"
},
CompressResponse = new TransactionTypeCompressResponse()
{
Value = false
}
}
};
string RQXML = GetXMLFromObject(messageHeader) + GetXMLFromObject(security) + GetXMLFromObject(ota_AirLowFareSearchRQ);
BargainFinderMaxRQResponse response = await bargainFinderMaxPortTypeClient.BargainFinderMaxRQAsync(messageHeader, security, ota_AirLowFareSearchRQ);
}
}
public static string GetXMLFromObject(object o)
{
StringWriter sw = new StringWriter();
System.Xml.XmlTextWriter tw = null;
try
{
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(o.GetType());
tw = new System.Xml.XmlTextWriter(sw);
serializer.Serialize(tw, o);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
sw.Close();
if (tw != null)
{
tw.Close();
}
}
return sw.ToString();
}
< /code>
Вот как я инициализации объекта: < /p>
ota_AirLowFareSearchRQ.OriginDestinationInformation[0] = new OTA_AirLowFareSearchRQOriginDestinationInformation()
{
RPH = "1",
Item = model.DepartureDate.Value.ToString("yyyy-MM-ddTHH:mm:ss"),
ItemElementName = ItemChoiceType.DepartureDateTime, // I want this element to be serialized
OriginLocation = new OriginDestinationInformationTypeOriginLocation()
{
LocationCode = model.DepartureFrom
},
DestinationLocation = new OriginDestinationInformationTypeDestinationLocation()
{
LocationCode = model.ArrivalTo
},
};
Однако при сериализации этого объекта в выходных данных XML используется вместо :
2024-08-04T00:00:00
Подробнее здесь: https://stackoverflow.com/questions/793 ... in-my-gene
Почему XmlSerializer выводит неправильное значение перечисления для ItemChoiceType в моем сгенерированном классе? (API B ⇐ C#
Место общения программистов C#
1737716565
Anonymous
Я работаю со сгенерированным классом C#, используя System.Xml.Serialization.XmlSerializer для сериализации объекта в XML. Созданный класс включает перечисление ItemChoiceType и свойство ItemElementName, которое определяет, какой XML-элемент сериализовать. Вот соответствующая часть сгенерированного кода:
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.2.0-preview1.23462.5")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.opentravel.org/OTA/2003/05", IncludeInSchema=false)]
public enum ItemChoiceType
{
DepartureDateTime,
ArrivalDateTime,
ArrivalDates,
DepartureDates,
}
[System.Xml.Serialization.XmlElementAttribute(Order=1)]
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemChoiceType ItemElementName
{
get
{
return this.itemElementNameField;
}
set
{
this.itemElementNameField = value;
}
}
[System.Xml.Serialization.XmlElementAttribute("ArrivalDateTime", typeof(string), Order=0)]
[System.Xml.Serialization.XmlElementAttribute("ArrivalDates", typeof(TravelDateTimeTypeArrivalDates), Order=0)]
[System.Xml.Serialization.XmlElementAttribute("DepartureDateTime", typeof(string), Order=0)]
[System.Xml.Serialization.XmlElementAttribute("DepartureDates", typeof(TravelDateTimeTypeDepartureDates), Order=0)]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
public object Item
{
get
{
return this.itemField;
}
set
{
this.itemField = value;
}
}
< /code>
Это мой фактический метод для картирования значения для модели и конвертирования в XML. < /p>
public async Task bargainFinder(FlightSearchDTO model)
{
try
{
if (string.IsNullOrEmpty(model.DepartureDateString) == false)
{
model.DepartureDate = Convert.ToDateTime(model.DepartureDateString);
}
if (string.IsNullOrEmpty(model.ReturnDateString) == false)
{
model.ReturnDate = Convert.ToDateTime(model.ReturnDateString);
}
string endpoint = sabreSetting.SessionCreateEndPoint;
string ipcc = sabreSetting.IPCC;
string convId = sabreSetting.ConversationId;
string binarySecurityToken = @"Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/ACPCRTD!ICESMSLB\/CRT.LB!-2776506000596342904!1865259!0";
string seatClass = "";
SabreSessionDTO sessionDetail = await _sabreSessionService.GetSabreSessionById(model.SessionId);
if (sessionDetail == null || sessionDetail.ExpireOn < DateTime.Now || sessionDetail.IsExpired == true)
{
model.SessionId = await sessionCreate(sessionDetail.FlightSearchId ?? 0);
sessionDetail = await _sabreSessionService.GetSabreSessionById(model.SessionId);
}
binarySecurityToken = sessionDetail.SecurityToken;
convId = sessionDetail.ConversationId;
ipcc = sabreSetting.IPCC;
EndpointAddress url = new EndpointAddress(new Uri(endpoint));
Binding binding = new BasicHttpsBinding()
{
MaxReceivedMessageSize = Int32.MaxValue,
MaxBufferSize = Int32.MaxValue
};
BargainFinderMaxPortTypeClient bargainFinderMaxPortTypeClient = new BargainFinderMaxPortTypeClient(binding, u r l ) ; < b r / > < b r / > B a r g a i n F i n d e r M a x . M e s s a g e H e a d e r m e s s a g e H e a d e r = n e w B a r g a i n F i n d e r M a x . M e s s a g e H e a d e r ( ) < b r / > { < b r / > F r o m = n e w F r o m ( ) < b r / > { < b r / > P a r t y I d = n e w P a r t y I d [ ] < b r / > { < b r / > n e w P a r t y I d ( ) < b r / > { < b r / > V a l u e = i p c c < b r / > } < b r / > } < b r / > } , < b r / > T o = n e w T o ( ) < b r / > { < b r / > P a r t y I d = n e w P a r t y I d [ ] < b r / > { < b r / > n e w P a r t y I d ( ) < b r / > { < b r / > V a l u e = e n d p o i n t < b r / > } < b r / > } < b r / > } , < b r / > C o n v e r s a t i o n I d = c o n v I d , < b r / > C P A I d = i p c c , < b r / > S e r v i c e = n e w B a r g a i n F i n d e r M a x . S e r v i c e ( ) < b r / > { < b r / > V a l u e = & q u o t ; B a r g a i n F i n d e r M a x R Q & q u o t ; < b r / > } , < b r / > A c t i o n = & q u o t ; B a r g a i n F i n d e r M a x R Q & q u o t ; , < b r / > M e s s a g e D a t a = n e w M e s s a g e D a t a ( ) < b r / > { < b r / > M e s s a g e I d = & q u o t ; 2 0 2 5 0 1 1 9 - 1 2 1 4 5 4 1 7 1 - 7 5 1 8 . B A R G A I N F I N D E R M A X R S @ w e b s e r v i c e s . s a b r e . c o m & q u o t ; , < b r / > T i m e s t a m p = D a t e T i m e . U t c N o w . T o S t r i n g ( & q u o t ; y y y y - M M - d d T H H : m m : s s K & q u o t ; ) , < b r / > T i m e T o L i v e = D a t e T i m e . U t c N o w < b r / > } , < b r / > D e s c r i p t i o n = n e w D e s c r i p t i o n [ ] < b r / > { < b r / > n e w D e s c r i p t i o n < b r / > { < b r / > V a l u e = & q u o t ; B a r g a i n F i n d e r M a x S e r v i c e & q u o t ; < b r / > } < b r / > } < b r / > } ; < b r / > < b r / > B a r g a i n F i n d e r M a x . S e c u r i t y s e c u r i t y = n e w B a r g a i n F i n d e r M a x . S e curity()
{
BinarySecurityToken = binarySecurityToken
};
OTA_AirLowFareSearchRQ ota_AirLowFareSearchRQ = new OTA_AirLowFareSearchRQ();
ota_AirLowFareSearchRQ.Version = "6.9.0";
ota_AirLowFareSearchRQ.AvailableFlightsOnly = true;
//ota_AirLowFareSearchRQ.AvailableFlightsOnlySpecified = true;
ota_AirLowFareSearchRQ.ResponseType = "OTA";
ota_AirLowFareSearchRQ.Target = OTA_AirLowFareSearchRQTarget.Production;
ota_AirLowFareSearchRQ.POS = new POS_Type
{
Source = new SourceType[]
{
new SourceType
{
PseudoCityCode =ipcc,
RequestorID = new UniqueID_Type()
{
ID = "1",
Type = "1",
CompanyName = new CompanyNameType()
{
Code = "TN",
Value = "TN"
}
}
}
}
};
if (model.TripType == 1)
{
ota_AirLowFareSearchRQ.OriginDestinationInformation = new OTA_AirLowFareSearchRQOriginDestinationInformation[1];
ota_AirLowFareSearchRQ.OriginDestinationInformation[0] = new OTA_AirLowFareSearchRQOriginDestinationInformation()
{
RPH = "1",
ItemElementName = ItemChoiceType.DepartureDateTime,
Item = model.DepartureDate.Value.ToString("yyyy-MM-ddTHH:mm:ss"),
OriginLocation = new OriginDestinationInformationTypeOriginLocation()
{
LocationCode = model.DepartureFrom
},
DestinationLocation = new OriginDestinationInformationTypeDestinationLocation()
{
LocationCode = model.ArrivalTo
}
};
}
if (model.TripType == 2)
{
ota_AirLowFareSearchRQ.OriginDestinationInformation = new OTA_AirLowFareSearchRQOriginDestinationInformation[2];
ota_AirLowFareSearchRQ.OriginDestinationInformation[0] = new OTA_AirLowFareSearchRQOriginDestinationInformation()
{
RPH = "1",
ItemElementName = ItemChoiceType.DepartureDateTime,
Item = model.DepartureDate.Value.ToString("yyyy-MM-ddTHH:mm:ss"),
OriginLocation = new OriginDestinationInformationTypeOriginLocation()
{
LocationCode = model.DepartureFrom
},
DestinationLocation = new OriginDestinationInformationTypeDestinationLocation()
{
LocationCode = model.ArrivalTo
},
TPA_Extensions = new OTA_AirLowFareSearchRQOriginDestinationInformationTPA_Extensions
{
SegmentType = new ExchangeOriginDestinationInformationTypeSegmentType
{
Code = ExchangeOriginDestinationInformationTypeSegmentTypeCode.O
}
}
};
ota_AirLowFareSearchRQ.OriginDestinationInformation[1] = new OTA_AirLowFareSearchRQOriginDestinationInformation()
{
RPH = "2",
ItemElementName = ItemChoiceType.DepartureDateTime,
Item = model.ReturnDate.Value.ToString("yyyy-MM-ddTHH:mm:ss"),
OriginLocation = new OriginDestinationInformationTypeOriginLocation()
{
LocationCode = model.ArrivalTo
},
DestinationLocation = new OriginDestinationInformationTypeDestinationLocation()
{
LocationCode = model.DepartureFrom
},
TPA_Extensions = new OTA_AirLowFareSearchRQOriginDestinationInformationTPA_Extensions
{
SegmentType = new ExchangeOriginDestinationInformationTypeSegmentType
{
Code = ExchangeOriginDestinationInformationTypeSegmentTypeCode.O
}
}
};
}
if (model.TripType == 3 && model.MulticityItems != null && model.MulticityItems.Count > 0)
{
ota_AirLowFareSearchRQ.OriginDestinationInformation = new OTA_AirLowFareSearchRQOriginDestinationInformation[model.MulticityItems.Count];
int cityCount = 1;
foreach (var item in model.MulticityItems)
{
ota_AirLowFareSearchRQ.OriginDestinationInformation[cityCount - 1 ] = n e w O T A _ A i r L o w F a r e S e a r c h R Q O r i g i n D e s t i n a t i o n I n f o r m a t i o n ( ) < b r / > { < b r / > R P H = c i t y C o u n t . T o S t r i n g ( ) , < b r / > I t e m E l e m e n t N a m e = I t e m C h o i c e T y p e . D e p a r t u r e D a t e T i m e , < b r / > I t e m = C o n v e r t . T o D a t e T i m e ( i t e m . D e p a r t u r e D a t e S t r i n g ) . T o S t r i n g ( & q u o t ; y y y y - M M - d d T H H : m m : s s & q u o t ; ) , < b r / > O r i g i n L o c a t i o n = n e w O r i g i n D e s t i n a t i o n I n f o r m a t i o n T y p e O r i g i n L o c a t i o n ( ) < b r / > { < b r / > L o c a t i o n C ode = item.DepartureFrom
},
DestinationLocation = new OriginDestinationInformationTypeDestinationLocation()
{
LocationCode = item.ArrivalTo
},
TPA_Extensions = new OTA_AirLowFareSearchRQOriginDestinationInformationTPA_Extensions
{
SegmentType = new ExchangeOriginDestinationInformationTypeSegmentType
{
Code = ExchangeOriginDestinationInformationTypeSegmentTypeCode.O
}
}
};
cityCount++;
}
}
AirTripType tripTypeValue = new AirTripType();
if (model.TripType == 1)
{
tripTypeValue = AirTripType.OneWay;
}
if (model.TripType == 2)
{
tripTypeValue = AirTripType.Return;
}
if (model.TripType == 3)
{
tripTypeValue = AirTripType.OpenJaw;
}
if (model.SeatClass 0)
{
totalPassengerType++;
totalPassenger = model.TravellerAdult;
}
if (model.TravellerChildren > 0)
{
totalPassengerType++;
totalPassenger += model.TravellerChildren;
}
if (model.TravellerInfant > 0)
{
totalPassengerType++;
totalPassenger += model.TravellerInfant;
}
ota_AirLowFareSearchRQ.TravelerInfoSummary = new TravelerInfoSummaryType()
{
SeatsRequested = new[]
{
totalPassenger.ToString()
}
};
ota_AirLowFareSearchRQ.TravelerInfoSummary.AirTravelerAvail = new TravelerInformationType[] {
new TravelerInformationType()
};
ota_AirLowFareSearchRQ.TravelerInfoSummary.AirTravelerAvail[0].PassengerTypeQuantity = new PassengerInfoType[totalPassengerType];
int travelerType = 0;
if (model.TravellerAdult > 0)
{
ota_AirLowFareSearchRQ.TravelerInfoSummary.AirTravelerAvail[0].PassengerTypeQuantity[travelerType] = new PassengerInfoType()
{
Code = "ADT",
Quantity = model.TravellerAdult.ToString()
};
travelerType++;
};
if (model.TravellerChildren > 0)
{
ota_AirLowFareSearchRQ.TravelerInfoSummary.AirTravelerAvail[0].PassengerTypeQuantity[travelerType] = new PassengerInfoType()
{
Code = "CNN",
Quantity = model.TravellerChildren.ToString()
};
travelerType++;
};
if (model.TravellerInfant > 0)
{
ota_AirLowFareSearchRQ.TravelerInfoSummary.AirTravelerAvail[0].PassengerTypeQuantity[travelerType] = new PassengerInfoType()
{
Code = "INF",
Quantity = model.TravellerInfant.ToString()
};
travelerType++;
};
ota_AirLowFareSearchRQ.TPA_Extensions = new OTA_AirLowFareSearchRQTPA_Extensions()
{
IntelliSellTransaction = new TransactionType()
{
RequestType = new TransactionTypeRequestType()
{
Name = sabreSetting.NumberOfResult + "ITINS"
},
CompressResponse = new TransactionTypeCompressResponse()
{
Value = false
}
}
};
string RQXML = GetXMLFromObject(messageHeader) + GetXMLFromObject(security) + GetXMLFromObject(ota_AirLowFareSearchRQ);
BargainFinderMaxRQResponse response = await bargainFinderMaxPortTypeClient.BargainFinderMaxRQAsync(messageHeader, security, ota_AirLowFareSearchRQ);
}
}
public static string GetXMLFromObject(object o)
{
StringWriter sw = new StringWriter();
System.Xml.XmlTextWriter tw = null;
try
{
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(o.GetType());
tw = new System.Xml.XmlTextWriter(sw);
serializer.Serialize(tw, o);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
sw.Close();
if (tw != null)
{
tw.Close();
}
}
return sw.ToString();
}
< /code>
Вот как я инициализации объекта: < /p>
ota_AirLowFareSearchRQ.OriginDestinationInformation[0] = new OTA_AirLowFareSearchRQOriginDestinationInformation()
{
RPH = "1",
Item = model.DepartureDate.Value.ToString("yyyy-MM-ddTHH:mm:ss"),
ItemElementName = ItemChoiceType.DepartureDateTime, // I want this element to be serialized
OriginLocation = new OriginDestinationInformationTypeOriginLocation()
{
LocationCode = model.DepartureFrom
},
DestinationLocation = new OriginDestinationInformationTypeDestinationLocation()
{
LocationCode = model.ArrivalTo
},
};
Однако при сериализации этого объекта в выходных данных XML используется вместо :
2024-08-04T00:00:00
Подробнее здесь: [url]https://stackoverflow.com/questions/79383472/why-does-xmlserializer-output-the-wrong-enum-value-for-itemchoicetype-in-my-gene[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия