Looking at the WDSL on a webservice. the xml states that the datatype is an integer, however, when calling the web method the method expect a string, WDSL code below
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType:="integer", Order:=0)> _
Public Property ID() As String
Get
Return Me.ID
End Get
Set(value As String)
Me.ID= value
End Set
End Property
Is this correct? I am confused as of why it requires a string to be passed if the serialization is saying the type in an integer?
My experience is telling me that on their side i.e. server, that they will cast the string into an integer? correct?
Thanks
xsd:integer. The integer data type accepts any decimal literal value, in which the decimal point is omitted from the lexical representation.
Description. The lexical and value spaces of xsd:string are the set of all possible strings composed of any character allowed in a XML 1.0 document without any treatment done on whitespace.
The integer data type is used to specify a numeric value without a fractional component. The following is an example of an integer declaration in a schema: <xs:element name="price" type="xs:integer"/>
This turns out to be a surprisingly good question that touches on some subtleties of XSD and how it can be mapped to a .NET language like C# or VB.NET.
The XSD type in your WSDL is of type xs:integer
. The XML Schema specification defines xs:integer as unbounded. This in contrast to xs:int, which is bounded to 32 bit.
If your WSDL were to use xs:int
instead, you would find the WSDL importer to map it to an Int32
.
While implementations are allowed to impose restrictions on xs:integer
, for instance by setting the range to be limited by a machine's word size (which can be any size), it is good practice to "Be liberal in what you accept, and conservative in what you send".
Since .NET did not have a native BigInteger type until recently, the only option to be able to send or receive the full range of values of xs:intger
is by taking a data type that allows unlimited ranges and they chose string
. I may have preferred a datatype that is itself limited to accepting only digits, but there's something to say for the fact that they chose a core datatype.
They apply similar methods to other datatypes, for different reasons. For instance, gYearMonth
could have been mapped to a DateTime
type, setting the other values to zero when sending. But again they chose string
.
Here is a full list of the mappings that Microsoft uses when importing WSDL.
on their side i.e. server, they will cast the string into an integer? correct?
No. It works somewhat as follows (roughly):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With