470,833 Members | 1,379 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

minOccurs="1" for webmethod array parameter

Right now I'm getting this in the wsdl:
<s:element minOccurs="0" maxOccurs="1" name="Items"
type="tns:ArrayOfMyClass" />
I would like to get minOccurs="1" for this webmethod:

[WebMethod]
public string HelloWorld(MyClass[] Items)
{
return "Hello";
}
I've tried this :
[WebMethod]
public string
HelloWorld([System.Xml.Serialization.XmlElementAttribute(IsNul lable =
true)] MyClass[] Items)
{
return "Hello";
}

but I still get minOccurs="0" and the problem seems to be a result that
Items is an array.
Apr 18 '06 #1
2 3511
Thank you for posing in the MSDN newsgroup.

As for the WebMethod Parameter object's XSD Schema description, it will
follow the following rule:

1. If the paramter is of value type, such as those primitive types, int,
long ,.... or some other structs like Datetime, the minOccurs for element
in <sequence> is assigned to "1". This is because value type should always
has a certain valid instance existed.

2.If the parameter is of reference type, such as string, or other classes,
the minOccurs attribute for the element will always be 0, because for
reference type in .NET, it could be set to "Null" which correspond to the
minOccurs=0.

so for your scenario, if you do want to make the paramter be declared as
minOccurs=1 in the XSD schema, you may consider use a ValueType class(in c#
, use "struct" keyword to declare the type) to encapsulate that
ArrayObject.

Thanks & Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 19 '06 #2
=The best way will be to treat the array as a contained array when it's
serialized. At the moment you just have it outputting as a list of
elements, hence the minimum has to be zero as there might not be
anything in the array.

using System.Xml.Serialization;

[WebMethod]
public string HelloWord(
[XmlArray("items", IsNullable=true), XmlArrayItem("item",
typeof(MyClass))] MyClass[] items)
{
return "Hello";
}

Josh
http://www.thejoyofcode.com/

Apr 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by joewhitehair | last post: by
5 posts views Thread by Mike Logan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.