Setting minOccurs="0" (not required) on web service parameters of type int
Posted
by Alex Angas
on Stack Overflow
See other posts from Stack Overflow
or by Alex Angas
Published on 2010-04-08T04:35:50Z
Indexed on
2010/04/08
5:03 UTC
Read the original article
Hit count: 244
ASP.NET
|web-services
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 addsnillable="true"
[XmlIgnore]
in the parameter declaration: the parameter is never output to the WSDL at all
© Stack Overflow or respective owner