Hi,
Default values happen in a few ways. From a contract basis, your only tool
is XML schema. The schema language does allow one to define default values
for optional fields. In this way, if someone fails to send a field, the
receiving party, when equipped with a schema aware reader, can have the
reader fill in the defaults for them.
In ASP.Net, the reader that is normally used as part of the deserializaiton
process does NOT use the schema (it is an optimized pull-based reader that
was created by looking at the schema at one point). Thus, the default
behavior for serialized classes (perhaps created with XSD.exe or
XmlObjectGen.exe) does NOT apply defaults.
To change this, you have a few options. First, you can pass the XML as
received thru a validating reader before it is processed by the default XML
serializer. This is easy enough to do and you can use the Web Service
Extension mechanism to accomplish this. In this way you alter the received
XML before ASP.net deserializes it. If you use a validating reader and
preloaded schema cache, the defaults will be added for you - and you pass
the altered XML stream on to the default serializer.
Another way to do this is to change your constructors (in both the server
side class and any proxy logic generated by add-web-reference) so that the
values you want to see are there, so that if an optional element or
attribute wasn't present when serialized (or on class_new), the default
values are available.
I hope this helps
Dan Rogers
Microsoft Corporation
--------------------
NNTP-Posting-Date: Tue, 14 Dec 2004 13:20:26 -0600
From: Matt D <md**********@yahoo.com>
Newsgroups: microsoft.public.dotnet.framework.webservices
Subject: Web service constants or default values
Date: Tue, 14 Dec 2004 12:20:25 -0700
Message-ID: <sn********************************@4ax.com>
X-Newsreader: Forte Agent 2.0/32.652
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 4
X-Trace:
sv3-S6UH2Evz25Y1XwEHtNs65ctZsXbT+lt3eqkVAgil7oli/WFQMWQ6gi9a1O3sry7W3jOWwOtr
gertlew!aNb3FbNYksqs8tAK/Uiw1F79fNkf+e4XjpxPDl+O488vUPUGtQwzGuPplvrsioCnRD7 +
X-Complaints-To:
ab***@giganews.com
X-DMCA-Notifications:
http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
X-Postfilter: 1.3.20
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!cpmsftn gxa06.phx.gbl!TK2MSFTNGP08
.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!border2.nntp.dca.giganews.co
m!border1.nntp.dca.giganews.com!nntp.giganews.com! local1.nntp.dca.giganews.c
om!news.giganews.com.POSTED!not-for-mail
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.webservices:8080
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
I have a bunch of constants used in my web services that the client
also needs to have. Is there a way to declare public properties that
are part of a class or structure as constants or at least give them a
default value through some XML shaping? Thanks.