Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / April 2006

Tip: Looking for answers? Try searching our database.

minOccurs="1"  for webmethod array parameter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NoNickname - 19 Apr 2006 00:36 GMT
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(IsNullable =
true)] MyClass[] Items)
   {
       return "Hello";
   }

but I still get  minOccurs="0"  and the problem seems to be a result that
Items is an array.
Steven Cheng[MSFT] - 19 Apr 2006 10:21 GMT
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.
Josh Twist - 19 Apr 2006 15:52 GMT
=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/

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.