I have an ASP.NET 2.0 web method with the following signature:
[WebMethod]
public QueryResult[] GetListData(
string url, string list, string query, int noOfItems, string titleField)
I'm running the disco.exe tool to generate .wsdl and .disco files from this web service for use in SharePoint. The following WSDL for the parameters is being generated:
<s:element minOccurs="0" maxOccurs="1" name="url" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="list" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="query" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="noOfItems" type="s:int" />
<s:element minOccurs="0" maxOccurs="1" name="titleField" type="s:string" />
Why does the int parameter have minOccurs set to 1 instead of 0 and how do I change it?
I've tried the following without success:
[XmlElementAttribute(IsNullable=false)]
in the parameter declaration: makes no difference (as expected when you think about it)
[XmlElementAttribute(IsNullable=true)]
in the parameter declaration: gives error "IsNullable may not be 'true' for value type System.Int32. Please consider using Nullable instead."
changing the parameter type to int? : keeps minOccurs="1"
and adds nillable="true"
[XmlIgnore]
in the parameter declaration: the parameter is never output to the WSDL at all
It's because an int
is not nullable that it must occur at least once, so setting IsNullable=false
probably isn't going to change anything. That said, I'm pretty sure IsNullable=true
doesn't help either, nor does making the object nullable.
From memory, I think you can do something like this though
[XmlIgnore]
public bool noOfItemsSpecified { get; set; }
public int noOfItems { get; set; }
That is, of course, if you wrap your arguments up in a single object that you can add this code to.
You can make the WSDL look the way you want with the following:
[WebMethod]
public QueryResult[] GetListData(
string url,
string list,
string query,
[XmlElement(DataType = "integer")] string noOfItems,
string titleField)
The idea is that you can tell the other party it must be a integer
but your internal type can be string
, therefore making the field not required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With