Filter by APML
Home
Archive
Contact
Log in
vlad navazhylau's blog
Agile Development, Architecture, .NET and The Art of Listening
<< Kimball University
|
Using a Custom WSDL File in ASP.NET Web Services >>
12.24.2007
In:
coding
|
web services
|
bad things happen to good people
Tags:
.NET
,
Web Services
,
When things go wrong
,
XML
0 Comments
Problems making a string property mandatory in Web Services
Source Link
I am developing a web service for a customer. The service has a method, that
returns an array of Forms. Each form has a Name property of Type String.
The customer wants the contract to specify, thath the name is mandatory and
not nullable. To reflect this, they want the xml in the wsdl (the Form part)
to look similar to this:
<xs:complexType name="Form">
<xs:sequence>
...
<xs:element minoccurs="1" maxoccurs="1" name="Name" nillable="false" type="xs:string">
...
So, minOccurs should be 1 and nillable should be false (or omitted), to
ensure the value is present and not null.
No matter how I go about this, however, I cannot make the wsdl generate the
desired values. I have tried to do contract-first development using WSCF from
thinktecture, and have the schema dictate the above values for minOccurs and
nillable, but this approach has not remedied the problem.
Is it at all possible to do what I want using .Net and Visual Studio 2005? I
hope my problem is described adequately, otherwise please request more
information. Any help is greatly appreciated.
Regarding on the webservice class property definition problem you
mentioned, here are some of my understanding and suggestion:
1. .NET webservice will always generate the xsd scheme for class property
as below:
** for value type(primitive types or struct), it will use minOccurs="1"
since value type will always be assigned a value(doesn't have null value
unless you use nullable type).
** for reference type(such as normal class), it will use minOccurs="0"
since value type will always support null value, the "string" type in your
case is just conform to this policy.
So far this rule is not changable in our custom code(attribute).
2. Also, XML XSD schema definition's element definition doesn't 100%
completely identical to .NET(or OO ) class/type definition. For example, if
you have the following xsd schema
<element minOccurs="1" ..../>
you can not find a reference type to mapping it since reference type always
support null reference value. I think you can consider define a wrapper
class(which inherit from ValueType ), property of such type will be
automatically generated as minOccurs="1" in XSD schema. However, you still
need to ensure that any sub property of reference type(such as string) has
been supplied a value in your own code.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Related posts
Using a Custom WSDL File in ASP.NET Web Services
http://www.pluralsight.com/blogs/craig/archive/2005/12/15/17482.aspx
Mindreef Solutions for Web Services and SOA
http://home.mindreef.com/products/soapscope-server/products.html
Configuring WSDL File Generation for ASP.NET Web Services
http://msdn2.microsoft.com/en-us/library/ms242476(vs.80).aspx
Comments are closed
I’m your host, Vlad Navazhylau, a software developer in Saint Louis.
More about me.
Search
tags
.NET
2005
Agile
AJAX
Architecture
ASP.NET
BI
Book
Cool
CSS
Database design
EAI
Enterprise Library
Helped with work
IDE
LINQ
Open Source
Patterns & Practices
People
Performance Tuning
SOA
SQL Server
Tools
T-SQL
Unit Testing
Useful stuff
Version Control
Web Services
When things go wrong
XML
Blogroll
ScottGu's Blog
Windows Azure: Announci...
Announcing the Release...
Windows Azure: New Virt...
Scott Hanselman
IE10 and IE11 and Windo...
Generating complex math...
CSI: Re-enabling Remote...
Rick Strahl
Routing to a Controller...
Prefilling an SMS on Mo...
Use IIS Application Ini...
Matt Cutts
Getting things done wit...
30 day challenge: bette...
Securing your Google Ac...
Billy McCafferty
Leveraging your XAML MV...
Leveraging your XAML MV...
Durandal vs. Framework...
Coding Horror
Martin Fowler
Download OPML file