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 |
|---|---|
| anyURI | System.Uri |
| base64Binary | System.Byte[] |
| Boolean | System.Boolean |
| Byte | System.SByte |
| Date | System.DateTime |
| dateTime | System.DateTime |
| decimal | System.Decimal |
| Double | System.Double |
| duration | System.TimeSpan |
| ENTITIES | System.String[] |
| ENTITY | System.String |
| Float | System.Single |
| gDay | System.DateTime |
| gMonthDay | System.DateTime |
| gYear | System.DateTime |
| gYearMonth | System.DateTime |
| hexBinary | System.Byte[] |
| ID | System.String |
| IDREF | System.String |
| IDREFS | System.String[] |
| int | System.Int32 |
| integer | System.Decimal |
| language | System.String |
| long | System.Int64 |
| month | System.DateTime |
| Name | System.String |
| NCName | System.String |
| negativeInteger | System.Decimal |
| NMTOKEN | System.String |
| NMTOKENS | System.String[] |
| nonNegativeInteger | System.Decimal |
| nonPositiveInteger | System.Decimal |
| normalizedString | System.String |
| NOTATION | System.String |
| positiveInteger | System.Decimal |
| QName | System.Xml.XmlQualifiedName |
| short | System.Int16 |
| string | System.String |
| time | System.DateTime |
| timePeriod | System.DateTime |
| token | System.String |
| unsignedByte | System.Byte |
| unsignedInt | System.UInt32 |
| unsignedLong | System.UInt64 |
| unsignedShort | System.UInt16 |
Nessun commento:
Posta un commento