473,321 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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 7015
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Raymond Hettinger | last post by:
Comments are invited on the following proposed PEP. Raymond Hettinger ------------------------------------------------------- PEP: 329
3
by: MLH | last post by:
I make API calls to the sndPlaySound function, something like this... XX% = sndPlaySound(msound, MyParm) Several predefined system constants (or API intrinsic constants) have been recommended...
11
by: Greenhorn | last post by:
Hi, K&R says that "floating point constants contain a decimal point (123.4) or an exponent (1e-2) or both; their type is double; unless suffixed. The suffixes f or F indicate a float constant; l...
9
by: Hardy Wang | last post by:
Hi all: I read an article from http://www.c-sharpcorner.com/Code/2003/Sept/InstallingWinServiceProgrammatically.asp about how to install a windows service programmatically. Based ont the code...
7
by: Don Wash | last post by:
Hi There! I'm trying to define constants so that I can refer those constants from any page of my ASP.NET website. I know I can use <appSettings> in web.config XML file but I don't want to parse...
5
by: OpticTygre | last post by:
What is the best way that anyone has found to capture errors inside a windows service? It's pointless to use compilation constants, as you can't "debug" a service very easily, and you can't pass...
11
by: Bill Nguyen | last post by:
I need to make a set of constants to be available for the whole application. Public const is confined to the form from which constants are declared. Is there a way to declare once and all forms can...
6
by: bsma1 | last post by:
I building a web service that has an enum I want the consuming application to be able to use. I have the enum declared in the web service as: public enum myEnum { ONE = 1, TWO = 2, };
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.