我有一个带有单一 Web 方法的 Web 服务:
[WebMethod]
public string SendInt([XmlElement(IsNullable=false)] int someInt)
{
return "Hello World";
}
此 Web 方法生成的 WSDL 包括以下几行:
<s:element name="SendInt">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="someInt" type="s:int"/>
</s:sequence>
</s:complexType>
</s:element>
WSDL 明确指出请求参数是一个 minOccurs=1 的值类型(int),但是当我使用 SoapUI 发送以下请求时:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:SendInt>
</tem:SendInt>
</soapenv:Body>
</soapenv:Envelope>
我从服务器获得了有效响应,而不是指示缺少someInt参数的错误。
在服务器中,我可以看到为someInt参数分配了一个 0 值。
这是正常行为吗?
如果是这样,我如何在我的 Web 方法中知道用户是否发送了 0 值或只是忘记发送此参数?
如果这不是正常行为,我该如何解决?