0

I have a web service with a single web method:

[WebMethod]
public string SendInt([XmlElement(IsNullable=false)] int someInt)
{
    return "Hello World";
}

The WSDL generated by this web method includes the following lines:

<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>

The WSDL clearly states that the request parameter is a value type (int) with a minOccurs=1 but when I am using SoapUI to send the following request:

<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>

I am getting a valid response from the server, instead of an error indicating that someInt parameter is missing.

In the server i can see that a 0 value is assigned to the someInt parameter.

Is this the normal behavior?

If so, how can I know in my web method if the user sent a 0 value or simply forgot to send this parameter?

If it is not a normal behavior how can I fix it?

Jaqen H'ghar
  • 16,186
  • 8
  • 49
  • 52

1 Answers1

1

Hey as you are specifying the element in the request it is there you just did not assign a value to it. The default value of int is 0 so yes this is normal behaviour. If you leave out the element you will get an invalid request. If they forgot to send this parameter then probably the whole element would not be present right. In that case the webservice would throw an error

Chino
  • 821
  • 6
  • 13
  • Sorry but I dont understand something I omitted the line `some integer value` How is the element in the request? Sorry if it is obvious but can you please expand little bit? – Jaqen H'ghar Aug 08 '15 at 14:58
  • Sure, in your wsdl you have the element SendInt right, you are using it in your soapUI request you have the element in there. Which means you did specify the element in the request but just did not assign a value to it. Which will then default to 0. – Chino Aug 08 '15 at 15:20
  • But in my WSDL, the minOccurs=1 is assigned to the **someInt** element and not to the **SendInt** element (which is the web method's name). As I understand it, in my request, I send only the web method's name, without the parameter element – Jaqen H'ghar Aug 08 '15 at 16:38