469,945 Members | 1,815 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

Web service constants or default values

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.
Nov 23 '05 #1
5 6782
You can have a separate class in the an ASMX class with static fields. You
could even have an enum if the values are related. WSDL will take care of
creating the correct proxy for the client.

Mujtaba.

"Matt D" <md**********@yahoo.com> wrote in message
news:sn********************************@4ax.com...
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.

Nov 23 '05 #2
Can you give me an example of this? I thought static fields are not
serialized by .NET. Thanks.

On Tue, 14 Dec 2004 14:52:29 -0500, "Mujtaba Syed"
<mu*****@marlabs.com> wrote:
You can have a separate class in the an ASMX class with static fields. You
could even have an enum if the values are related. WSDL will take care of
creating the correct proxy for the client.

Mujtaba.


Nov 23 '05 #3
I would recommend using default value in you WSDL schema type, thoug
some it means hand crafting your WSDL document, but that's should be too
hard, after you 've changed the wSDL generate the server stub(using
/server) and put the implemeation back on this stub

exmaple of Address type having default value for street

<complexType name="Address">
<sequence>
<element name="name" type="string" minOccurs="0"/>
<element name="street" type="string" default="Anystreet"/>
<element name="city" type="string"/>
</sequence>
</complexType>
Regards
Erymuzuan Mustapa

Matt D wrote:
Can you give me an example of this? I thought static fields are not
serialized by .NET. Thanks.

On Tue, 14 Dec 2004 14:52:29 -0500, "Mujtaba Syed"
<mu*****@marlabs.com> wrote:

You can have a separate class in the an ASMX class with static fields. You
could even have an enum if the values are related. WSDL will take care of
creating the correct proxy for the client.

Mujtaba.


Nov 23 '05 #4
>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.

Use an enum to define your constants and declare the properties with this
type. The WSDL will include a definition for your enum. This might also
improve your design since the constants no longer are "magic values", but
something defined strongly typed.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 23 '05 #5
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.

Nov 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Hardy Wang | last post: by
7 posts views Thread by Don Wash | last post: by
5 posts views Thread by OpticTygre | last post: by
6 posts views Thread by bsma1 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.