473,769 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7053
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**********@y ahoo.com> wrote in message
news:sn******** *************** *********@4ax.c om...
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*****@marlab s.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="Anystr eet"/>
<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*****@marlab s.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.ex e) 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**********@y ahoo.com>
Newsgroups: microsoft.publi c.dotnet.framew ork.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-S6UH2Evz25Y1XwE HtNs65ctZsXbT+l t3eqkVAgil7oli/WFQMWQ6gi9a1O3s ry7W3jOWwOtr
gertlew!aNb3FbN Yksqs8tAK/Uiw1F79fNkf+e4X jpxPDl+O488vUPU GtQwzGuPplvrsio CnRD7+
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.ph x.gbl!TK2MSFTNG XA01.phx.gbl!cp msftngxa06.phx. gbl!TK2MSFTNGP0 8
.phx.gbl!newsfe ed00.sul.t-online.de!t-online.de!borde r2.nntp.dca.gig anews.co
m!border1.nntp. dca.giganews.co m!nntp.giganews .com!local1.nnt p.dca.giganews. c
om!news.giganew s.com.POSTED!no t-for-mail
Xref: cpmsftngxa10.ph x.gbl
microsoft.publi c.dotnet.framew ork.webservices :8080
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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
1872
by: Raymond Hettinger | last post by:
Comments are invited on the following proposed PEP. Raymond Hettinger ------------------------------------------------------- PEP: 329
3
4238
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 for use as the 2nd parm... SND_ASYNC
11
5049
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 or L indicate a long double." the question is are these constants double by default unless suffixed with f or F ? Thanks in advance.
9
7027
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 sample, it provides the feature to install service under LocalSystem account. What I need is to install service under some other certian account. By further studying the code, and MSDN...
7
2563
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 and read the whole XML document everytime a page is requested. In classic ASP, I used Include files and define constants using Const keyword so that every page that has been included the file can refer the constants.
5
1574
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 in a command line arguement (can you?) to tell it to do something special like capture errors to a file while it's running. Has anyone figured out any good ways to do this type of run-time error capturing? Basically, if I were building a...
11
7787
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 access the constant values? Thanks Bill
6
10059
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
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.