Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

New Topic Post Reply
Guest
#1 Posted : Thursday, August 09, 2012 1:12:41 AM(UTC)
Quote
Guest
Rank: Guest

Joined: 12/12/2009(UTC)
Posts: 540

I have created an asp.net web service (.asmx) which takes in a custom object as input and returns the same object.
The custom object has many variables including some CHAR types.

Actual problem:
When i try to call the web service using SOAP UI and pass the value in the CHAR value as 'M' or any other alphabet, it throws the error that 'Input string was not in correct format'.

This is the exact error that i get:

Code:
oap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/
XMLSchema">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client
</faultcode>
         <faultstring>System.Web.Services.
Protocols.SoapException: 
Server was unable to read request. 
---> System.InvalidOperationException: 
There is an 
error in XML document (63, 51). --->
 System.FormatException: Input string 
was not in a correct format.
at System.Number.StringToNumber(String str, 
NumberStyles options, NumberBuffer&amp; 
number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseUInt32(String value, 
NumberStyles options, NumberFormatInfo numfmt)
   at System.UInt16.Parse(String s, 
NumberStyles style, NumberFormatInfo info)
   at System.UInt16.Parse(String s, 
NumberStyles style, IFormatProvider provider)
   at 
System.Xml.Serialization.XmlSerializationReader.
ToChar(String value)
   at Microsoft.Xml.Serialization.GeneratedAssembly.
XmlSerializationReader1.Read3_Salary
(Boolean isNullable, Boolean checkType)
   at Microsoft.Xml.Serialization.
GeneratedAssembly.
XmlSerializationReader1.Read4_calculate()
   at Microsoft.Xml.Serialization.
GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationReader reader)
   at System.Xml.Serialization.
XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, 
XmlDeserializationEvents events)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.
XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.
XmlSerializer.Deserialize(
XmlReader xmlReader, String encodingStyle)
   at System.Web.Services.Protocols.
SoapServerProtocol.ReadParameters()
   --- End of inner exception stack trace ---
   at System.Web.Services.Protocols.
SoapServerProtocol.ReadParameters()
   at System.Web.Services.Protocols.
WebServiceHandler.CoreProcessRequest()
</faultstring>
         <detail/>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>



The error shows that system is trying to convert the char into some number and then it fails. Not sure why it is trying to convert it to a number?

Any idea on how to resolve this error? I sthere any issue with the XMLSerializer?

Edited by user Thursday, August 09, 2012 1:17:53 AM(UTC)  | Reason: Not specified

Sponsor

Soan
#2 Posted : Thursday, August 09, 2012 1:21:31 AM(UTC)
Quote
Soan
Rank: Administration

Reputation:

Joined: 1/9/2010(UTC)
Posts: 449
Man
Location: India

Was thanked: 1 time(s) in 1 post(s)
This is basically an XML Serialization issue.
What is happening is that a class with a number of properties is being returned and serialized to XML.

However, for every property of a 'char' data type, what is serialized is not the char value, but rather the encoded (i.e. ASCII) numeric value.

This is not your code's issue. Rather, it looks like a bug in the XMLserializer class.

The workaround is to pass the the ASCII value of the character that you are passing as a char.
For example,
if you want to send char M, then send the ASCII 77 and things will work and the error would be gone.

<tem:character>M</tem:character>

should be replaced with

<tem:character>77</tem:character>

at the time of calling the web service.

Let me know if you can find any other workaround or have a better solution to tackle this situation.
Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.