How does .Net validates a soap request?
I have a WSDL that goes something like
<s:element name="CheckInStatus">
<s:complexType>
<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:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CheckInStatus 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
Drew Marsh - 10 Dec 2004 23:44 GMT
bebebutterfly@gmail.com
> How does .Net validates a soap request?
It doesn't do it for you....
> 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?
Because they didn't build that into the ASMX plumbing. The main reason for
this is that they expect you to be using the XmlSerializer which would error
on deserializing the incoming message if required data was missing or malformed.
It would have been nice if those of use working with XmlElement could have
had a property like ValidateRequest=true on WebMethodAttribute, but they've
left it up to you to do in this lower level scenario. So you need to wrap
your XmlElement with an XmlNodeReader and a ValidatingReader and do it yourself.
You can then throw your own soap fault to indicate the instance document
is invalid.
HTH,
Dre
Dan Rogers - 13 Dec 2004 21:29 GMT
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: bebebutterfly@gmail.com
Newsgroups: microsoft.public.dotnet.framework.webservices
Subject: WSDL Schema validation
Date: 10 Dec 2004 15:09:49 -0800
Organization: http://groups.google.com
Lines: 40
Message-ID: <1102720189.600458.250220@f14g2000cwb.googlegroups.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: groups-abuse@google.com
NNTP-Posting-Date: Fri, 10 Dec 2004 23:09:55 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To: groups-abuse@google.com
Injection-Info: f14g2000cwb.googlegroups.com; posting-host=64.139.57.2;
posting-account=WAq9Kw0AAAAeVc7OS2ltqeSGxRIn4kZ4
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.s
ul.t-online.de!t-online.de!news.glorb.com!postnews.google.com!f14g2000cwb.go
oglegroups.com!not-for-mail
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.webservices:8020
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
How does .Net validates a soap request?
I have a WSDL that goes something like
<s:element name="CheckInStatus">
<s:complexType>
<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:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CheckInStatus 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