当minOccurs = 1时,具有缺少int参数的SoapUI的Web服务请求会自动分配0值

时间:2015-08-08 12:35:00

标签: c# web-services wsdl soapui minoccurs

我有一个使用单一网络方法的网络服务:

[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明确指出request参数是一个值类型(int),minOccurs = 1但是当我使用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值。

这是正常行为吗?

如果是这样,我如何在我的网络方法中知道用户是否发送了0值或者只是忘了发送此参数?

如果这不是正常行为,我该如何解决?

1 个答案:

答案 0 :(得分:0)

嘿,因为你在请求中指定了元素,所以你只是没有为它赋值。 int的默认值为0,所以这是正常行为。如果遗漏该元素,您将收到无效请求。如果他们忘了发送这个参数,那么可能整个元素都不会正确存在。在这种情况下,webservice会抛出错误