我想知道是否可以为Web服务请求输入参数分配默认值。这是我在wsdl中的输入参数:
<element name="pensionType" default="0" type="int">
在代码方面,我检查了pensionType的值,如下所示:
if (pensionType!=0)
{ TODO code here}
else
{ return warning that no data found}
我在Mozilla Poster中测试了这个。因此,我预计,如果我没有为pensionType提供任何价值,我会收到警告。我收到一个很长的错误:
System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (13, 39). ---> System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Xml.XmlConvert.ToInt32(String s) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read44_getFileTypesRequest(Boolean isNullable, Boolean checkType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read45_getFileTypes(Boolean isNullable, Boolean checkType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read62_getFileTypes() at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer24.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(
答案 0 :(得分:1)
你可以这样做:
if(pensionType != null)
{
if (pensionType!=0)
{ TODO code here}
else
{ return warning that no data found}
}
这可能对你有帮助.. !!