Forum Discussion

PeceKr's avatar
PeceKr
New Contributor
9 years ago

SoapUI isn't serializing nullable int

I have datacontract with datamember of type nullable int .

 

 [DataMember(Order = 5,EmitDefaultValue = false)]
        public int? Zip { get; set; }

When I leave the Zip value empty and submit the request trough SoapUI I'm getting this error :

 

 <InnerException i:nil="true"/>
                        <Message>Input string was not in a correct format.</Message>
                        <StackTrace>at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&amp; number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Xml.XmlConvert.ToInt32(String s)
   at System.Xml.XmlConverter.ToInt32(String value)</StackTrace>
                        <Type>System.FormatException</Type>
                     </InnerException>
                     <Message>The value '' cannot be parsed as the type 'Int32'.</Message>
                     <StackTrace>at System.Xml.XmlConverter.ToInt32(String value)
   at System.Xml.XmlDictionaryReader.ReadElementContentAsInt()
   at System.Runtime.Serialization.XmlReaderDelegator.ReadElementContentAsInt()
   at ReadAddressSearchRequestFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
   at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
   at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract&amp; dataContract)
   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
   at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)</StackTrace>
                     <Type>System.Xml.XmlException</Type>
                  </InnerException>

When I run this through .net client , the request is serialized correctly and I'm getting good response.

Any ideas why I have this problem in SoapUI?

 

Thanks.

5 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    How does your request look like?

    Have you tried validating the same request?

    In the above excerpt, it is not showing exception from soapUI meaning it does not seem to be problem in soapUI, IMO.
    • PeceKr's avatar
      PeceKr
      New Contributor

      Here is my request :

       

      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://wowway.com/Care/Query">  
        <soapenv:Header/>
         <soapenv:Body>
            <com: SearchAddress>
               <!--Optional:-->
               <com:addressSearchRequest>
                  <!--Optional:-->
                  <com: Address1>Test</com:Address1>            
                  <com: State/>
                  <!--Optional:-->
                  <com: Zip/>
                  <!--Optional:-->
                  <com: UserName>Test</com:UserName>
               </com: addressSearchRequest>
            </com: SearchAddress>
         </soapenv:Body>
      </soapenv:Envelope>

      I have validation , but this error is thrown instantly from SoapUI, so I can't even debug it.

       

      If I validate the request in SoapUI , I'm getting error message saying  "Invalid decimal value: expected at least one digit" .

       

      Thanks.

      • nmrao's avatar
        nmrao
        Champion Level 3
        It is showing correct the error that is present in the request.
        <com: Zip/> is not valid as per the error.

        Make it like a valid one, such as
        <com: Zip>23456</com: Zip>