473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3675
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: joewhitehair | last post by:
Using the XSD.exe tool, I created a number of classes from my XSD file. When I generate the WSDL for my web service, the schema does not have the proper Occurance constraints for the attributes. In...
6
by: TS | last post by:
Hi, i have a problem validating xml against schema. I used http://apps.gotdotnet.com/xmltools/xsdvalidator/Default.aspx validator and it says it is fine. Can you tell me why this doesn't work? ...
3
by: Mike | last post by:
I have created a web service for a client to consume. The element I am having trouble with is, as described in their WSDL: <xsd:element minOccurs="0" ref="LocalData" maxOccurs="1" /> ...
5
by: Mike Logan | last post by:
I used WSDL.exe to generate a client side web proxy for a web service, called the web service, got the results but an array returned by the web service is not in the results. However if I use...
0
by: John Harvey | last post by:
I have been struggling with the following: I want to create a class that contains an array of some user-defined type. so I have the following vb code: Public Class Communications Public...
0
by: Bakunin | last post by:
Hi, I have a brief question regarding the .net framework renders class definitions of schemas to wsdl descritions. I have observed the following: 1. I have a schema with a mandatory field (in...
2
by: IsValidUN | last post by:
If an xsd indicates that an element within a doc is minOccurs="0" and you're using xsl to transform the doc do you have to do some kind of check prior to doing a transform on the element? For...
4
by: BorisBoshond | last post by:
Hi all, Hope someone is able and willing to help me with following problem. I received a xsd file from another company, our company i supposed to return xml based on that xsd. Problem is that I...
1
by: mato81 | last post by:
Hi all! I am a newbie to WSDL. I have a questions which has been driving me crazy... If I would have a WSDL with a types element somewhat like below, what is the point of the third last row...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.