The key issue here is you are trying to pass a null value to an integer -
which in .NET is a value type that cannot ever have a null value. When you
pass an empty element, you are supplying a null - and on serialization to
the integer, a value expeption is thrown. When you explicitely pass
"xs:nill="true" ", you are doing the same thing. This is just not allowed.
The key here is to recognize the difference between optional (no value
passed) and null value. The serializer does support optional values via
the "Specified" flag. If you have a property named "foo" and you choose to
make it optional, you just created a public boolean property named
fooSpecified in the implementation class along with your foo property.
When you serialize into that class, if no value was passed on the wire, the
specified flag will have a value of false. If a value was passed, the
specified flag will have a value of true. The same holds in reverse - if
you serialize a type that has an optional value out, and you don't set the
specified flag value to true beforehand, the field that the specified flag
is married to will not be serialized.
I hope this helps
Dan Rogers
Microsoft Corporation
--------------------
From:
be***********@g mail.com
Newsgroups: microsoft.publi c.dotnet.framew ork.webservices
Subject: WSDL Schema validation
Date: 10 Dec 2004 15:09:49 -0800
Organization:
http://groups.google.com
Lines: 40
Message-ID: <11************ **********@f14g 2000cwb.googleg roups.com>
NNTP-Posting-Host: 64.139.57.2
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google. com 1102720195 31184 127.0.0.1 (10 Dec 2004
23:09:55 GMT)
X-Complaints-To:
gr**********@go ogle.com
NNTP-Posting-Date: Fri, 10 Dec 2004 23:09:55 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To:
gr**********@go ogle.com
Injection-Info: f14g2000cwb.goo glegroups.com; posting-host=64.139.57. 2;
posting-account=WAq9Kw0 AAAAeVc7OS2ltqe SGxRIn4kZ4
Path:
cpmsftngxa10.ph x.gbl!TK2MSFTNG XA01.phx.gbl!TK 2MSFTNGP08.phx. gbl!newsfeed00. s
ul.t-online.de!t-online.de!news. glorb.com!postn ews.google.com! f14g2000cwb.go
oglegroups.com! not-for-mail
Xref: cpmsftngxa10.ph x.gbl
microsoft.publi c.dotnet.framew ork.webservices :8020
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.webservices
How does .Net validates a soap request?
I have a WSDL that goes something like
<s:element name="CheckInSt atus">
<s:complexTyp e>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="abcID" type="s:string"
/>
<s:element minOccurs="1" maxOccurs="1" name="myStatus" type="s:int"
/>
</s:sequence>
</s:complexType>
</s:element>
But when I pass a soap request below, no soap fault was returned.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelop e xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:soap="htt p://schemas.xmlsoap .org/soap/envelope/">
<soap:Body>
<CheckInStatu s xmlns="http://tempuri.org/">
<abcID>abc123 </abcID>
</CheckInStatus>
</soap:Body>
</soap:Envelope>
Passing a <myStatus /> or <myStatus xsi:nil="true"> would return a soap
fault.
I thought .Net should return a soap fault since the required element is
not passed, however it does not.
I validate the required field when the WS is invoked but I'm wondering
why that soap request was even permitted?
Thanks