martedì 5 febbraio 2013

XS Duration XML e String di Visual Studio


Un giorno ti capiterà SICURAMENTE di dover fare una chiamata a un webService passando anche un parametro che l'XML si aspetta sia di tipo DURATION. Tu sai dalla documentazione che per duration si intendono semplicemente dei giorni e Visual Studio ti dice che si aspetta una stringa. Cosa fai?

SEMPLICEMENTE, generi un nuovo TimeSpan con il numero dei giorni, new TimeSpan(2,0,0,0) e lo converti in stringa tramite XMLConvert.ToString().
Lui crea in questo caso la stringa P2D.
E tutto funziona.

FACILE, no?

Ecco l'esempio:

TimeSpan timeSpan = new TimeSpan(2,0,0,0);
string Duration = XmlConvert.ToString(timeSpan);



XML Schema (XSD) type.NET Framework type
anyURISystem.Uri
base64BinarySystem.Byte[]
BooleanSystem.Boolean
ByteSystem.SByte
DateSystem.DateTime
dateTimeSystem.DateTime
decimalSystem.Decimal
DoubleSystem.Double
durationSystem.TimeSpan
ENTITIESSystem.String[]
ENTITYSystem.String
FloatSystem.Single
gDaySystem.DateTime
gMonthDaySystem.DateTime
gYearSystem.DateTime
gYearMonthSystem.DateTime
hexBinarySystem.Byte[]
IDSystem.String
IDREFSystem.String
IDREFSSystem.String[]
intSystem.Int32
integerSystem.Decimal
languageSystem.String
longSystem.Int64
monthSystem.DateTime
NameSystem.String
NCNameSystem.String
negativeIntegerSystem.Decimal
NMTOKENSystem.String
NMTOKENSSystem.String[]
nonNegativeIntegerSystem.Decimal
nonPositiveIntegerSystem.Decimal
normalizedStringSystem.String
NOTATIONSystem.String
positiveIntegerSystem.Decimal
QNameSystem.Xml.XmlQualifiedName
shortSystem.Int16
stringSystem.String
timeSystem.DateTime
timePeriodSystem.DateTime
tokenSystem.String
unsignedByteSystem.Byte
unsignedIntSystem.UInt32
unsignedLongSystem.UInt64
unsignedShortSystem.UInt16

Nessun commento: