minOccurs=”1″ and ASP.NET web services

One of the projects that I’m working on involves putting
together a web service interface to a booking system so that
business partners can integrate our inventory into their business
systems. This involves exposing a fairly flexible schema so that
different partners can supply different information. This means
that for some requests some information is optional while for
requests from other partners that information might be
required.

Using ASP.NET web services, we implement this by having a class
to represent the whole request which contains object references to
other classes representing the optional information. In the schema,
we get a minOccurs=”0″ and maxOccurs=”1″ and this works well.

One of the things that I learnt this week, however, that hadn’t
been immediately apparent is that there is no way to insist that a
sub-object must be present: an [XmlRequired]
attribute if you will. This means that all reference types are
optional.

According to Douglas
Purdy
,

this behaviour is by design
:

If you already know what you want on the wire, why
don’t you define the WSDL first? You can use the wsdl.exe tool with
the /server option to generate the code.

He says this Usenet post will be taken as a feature request – I
presume nothing has been done yet and that this therefore may or
may not exist in v2.0. It sure would be useful. Keeping our WSDL in
sync with our code manually would be a pain, but we’d like the WSDL
schema to represent most of the contract to our customers.