I am accessing a third-party web service written in php. The service wsdl is added as a web reference in my project and works ok most of the times.
Now a problem I often run into is the following :
The parameters in the wsdl have their type defined (string, bool, int), but they don't have the nillable attribute set. Now often int or bool are returned as empty elements in the response, which throws a conversion error :
[FormatException: 开发者_开发百科Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +9594283
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
System.Xml.XmlConvert.ToInt32(String s) +43
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReadernutritionService.Read6_NullableOfInt32(Boolean checkType) +125
What I do now to fix this is change all parameter types to string's, so they don't throw errors on empty elements. I don't like this solution at all, so I was wondering if I could override this somehow so that when the element is empty, I can simply fill in 0 for int, and false for bool.
Any suggestions?
The simplest solution is to make a local copy of the WSDL, make the required changes and then call that. You could attempt to get fancy and write scripts that do this dynamically, but you probably are asking for more trouble than its worth.
精彩评论