473,583 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to specifiy default values in WCF web services (repost)

Hello,

I am trying to specify a logical default value for a [DataMember] in a WCF
Web Service using basicHttpBindin g.

I realize that the language defaults are:

int - 0
string - null
bool - false
enum - ?

I tried using OnDeserializing and OnDeserialized events, but when the client
doesn't explicitely set the value for an int member, for instance, I keep
getting 0. For a bool memeber I get a 'false', and for an enum member it
picks some default, but I don't know how it picks it. The only default that
I can logically work with is the null for reference types, including
strings.

The XSD allows you to specify "default=" attribute for a member, but in WCF
I don't have control over wsdl/schema generation. So I thought there would
be a way to specify a logical default value for a DataMember through an
Attribute settings of some sort, but I can't find one.

Please help!!!

thanks, Dave
Jul 15 '08 #1
4 17259
Hi Dave,

From your description, you're wondering how to set some default value for
some primitive types (int , bool, enum ..) contained in WCF data contract
class, correct?

Yes, .NET Framework has some default values for primitive types such as
integer, bool, .... For WCF DataContract class, the "DataMemberAttr ibute"
hs some property for control the serlization behavior of default value of
field:
#Data Member Default Values
http://msdn.microsoft.com/en-us/library/aa347792.aspx
Also, WCF data contract class is the same as other normal class, if you
have some class fields which want to have some default value, you can put
the default value in the field's declaration( or in the class's default
constructor). e.g.

=============== ===
[DataContract]
public class MyTestDC
{
private int _count = -1;
private bool _valid;

[DataMember]
public bool Valid
{
get { return _valid; }
set { _valid = value; }
}

[DataMember]
public int Count
{
get { return _count; }
set { _count = value; }
}

public MyTestDC()
{
_valid = false;
}

}
=============== ==========

http://blogs.parivedasolutions.com/j...09/11/523.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: "Dave Burns" <db****@newsgro up.nospam>
Subject: How to specifiy default values in WCF web services (repost)
Date: Tue, 15 Jul 2008 10:12:58 -0500

Hello,

I am trying to specify a logical default value for a [DataMember] in a WCF
Web Service using basicHttpBindin g.

I realize that the language defaults are:

int - 0
string - null
bool - false
enum - ?

I tried using OnDeserializing and OnDeserialized events, but when the client
doesn't explicitely set the value for an int member, for instance, I keep
getting 0. For a bool memeber I get a 'false', and for an enum member it
picks some default, but I don't know how it picks it. The only default that
I can logically work with is the null for reference types, including
strings.

The XSD allows you to specify "default=" attribute for a member, but in WCF
I don't have control over wsdl/schema generation. So I thought there would
be a way to specify a logical default value for a DataMember through an
Attribute settings of some sort, but I can't find one.

Please help!!!

thanks, Dave

Jul 16 '08 #2
Language defaults don't work for me, because they are not logical defaults.

The [EmitDefaultValu e=false] only works for microsoft clients using svcutil
generated proxy file, correct? What if it's a Java client consuming my WCF
service? How can I be sure that what came over the wire is a language
default value or my logical default value?

Here's a concrete example:

I have a property called PerfectPrintAng le, it's an integer.
Its logical default value is -1, which tells the web service not to use
PerfectPrintAng le (valid values are from 0 to 359)
Its language default value is 0, which is in the correct range.

So if it comes in over the wire as 0 (language default), the web service has
no way of telling whether this was defaulted on the client side or actually
set to 0 by the client program.

I hope I am explaining this correctly!

Thanks, Dave
Jul 17 '08 #3
Thanks for your reply Dave,

I think I've got the actual issue you mentioned. Actually, you want to find
some means to let the wcf client get informed of the certain default value
for a certain field(no matter what programming platform the client is
using). I'm afraid this is abit difficult since for default value, this
is mostly a programming language layer feature, for example .net framework
class can set default value for class members. The WCF or webservice are
exposing service via WSDL/xml schema , it is difficult to let XML
description to force the client side programming platform generate code
which follow a logical rule. So far I haven't found such a means in xml
schema. For example, you can add some xml annotation/comments to indicate
the client side that what's the expected value/default value for the
certain field, however, it is still depend on the client-side's proxy
implementation (whether it adopt the annotation or WSDL description or
not).

So far I think the most guranteed means is still make sure both sides using
.net framework (actually this is the preferred approach for WCF ) so that
we can enforce such logical rules via code level definition such as default
value (or constructor initialization) .

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Dave Burns" <db****@newsgro up.nospam>
References: <#x************ **@TK2MSFTNGP05 .phx.gbl>
<H2************ **@TK2MSFTNGHUB 02.phx.gbl>
Subject: Re: How to specifiy default values in WCF web services (repost)
Date: Thu, 17 Jul 2008 08:31:21 -0500
Language defaults don't work for me, because they are not logical defaults.

The [EmitDefaultValu e=false] only works for microsoft clients using svcutil
generated proxy file, correct? What if it's a Java client consuming my WCF
service? How can I be sure that what came over the wire is a language
default value or my logical default value?

Here's a concrete example:

I have a property called PerfectPrintAng le, it's an integer.
Its logical default value is -1, which tells the web service not to use
PerfectPrintAng le (valid values are from 0 to 359)
Its language default value is 0, which is in the correct range.

So if it comes in over the wire as 0 (language default), the web service
has
no way of telling whether this was defaulted on the client side or actually
set to 0 by the client program.

I hope I am explaining this correctly!

Thanks, Dave

Jul 18 '08 #4
Hi Dave,

Have you got any progress on this or still any further questions or
anything we can help?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

From: st*****@online. microsoft.com (Steven Cheng [MSFT])
Organization: Microsoft
Date: Fri, 18 Jul 2008 06:55:07 GMT
Subject: Re: How to specifiy default values in WCF web services (repost)
Thanks for your reply Dave,

I think I've got the actual issue you mentioned. Actually, you want to find
some means to let the wcf client get informed of the certain default value
for a certain field(no matter what programming platform the client is
using). I'm afraid this is abit difficult since for default value, this
is mostly a programming language layer feature, for example .net framework
class can set default value for class members. The WCF or webservice are
exposing service via WSDL/xml schema , it is difficult to let XML
description to force the client side programming platform generate code
which follow a logical rule. So far I haven't found such a means in xml
schema. For example, you can add some xml annotation/comments to indicate
the client side that what's the expected value/default value for the
certain field, however, it is still depend on the client-side's proxy
implementation (whether it adopt the annotation or WSDL description or
not).

So far I think the most guranteed means is still make sure both sides using
.net framework (actually this is the preferred approach for WCF ) so that
we can enforce such logical rules via code level definition such as default
value (or constructor initialization) .

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Jul 22 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3373
by: Tony Williams | last post by:
SORRY I know we shouldn't do this but I'm desperate for an answer to this and the previous post didn't seem to get a response. I have a table with two fields, txtvalue (a number field) and txtmonth ( a date/time field). I want to create a report that shows the difference in value between the value in txtvalue in one value of txtmonth and the...
5
1889
by: Wade Redmond | last post by:
I'm trying to consume a .net web service with VC++.net. It works fine without SSL but will not work at all with SSL and no exception is thrown. Can someone please explain possible causes as to why this is happening? By the way, no client certificate is required and you can browse to the URL in IE with no problem, no messages, etc. tia...
5
7038
by: Matt D | last post by:
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.
5
19576
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was having a problem in the calling program. I searched online and found suggestions that I return an Array instead so I modified my code (below) to return...
6
1354
by: Materialised | last post by:
Hi All I have been searching the net on this for the last couple of hours to no avail. I need to fill a datagridview control based on the values entered in 2 text boxes. However I cant for the life of me figure out who to do this. Here is my SQL statement:
2
2096
by: gbanister | last post by:
I'd like to repost a message that I found in this group almost one year ago, because it's the exact problem I'm in and there was no solution offered to this post last year. (note: I was not the original author of the below post) I have similar issue sharing types between the web services, and also the client consuming those web services....
2
1862
by: Arvind Ganesan | last post by:
Hi, I would like to write a service in C# and I have the need to display a UI with status information, statistics, etc. If I use the Windows Service project in C#, I noticed that the System.Windows namespace is not available to me in the intellisense when I type "using System.". What is the recommended procedure in C# / .NET for...
10
9657
by: =?Utf-8?B?SmFtZXMgV29uZw==?= | last post by:
Hi everybody, I'm trying to use the new VB 2008 right now and I want to know how to preset the company name and copyright informtion in Assembly Information. In my current VB 2005, company name and copyright information (the word "CopyRight" with company name and year) is filled in automatically once a new project is created. However, I...
3
1693
by: cj2 | last post by:
In the code below I want when this web service is first published for the boolean Running.running to be True. It seems to default to false. How can I make this default to True? Once the web service is running and I call it with "start" it works fine as coded. I just don't want to have to call it with start the first time. Imports...
0
7827
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7936
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8195
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...
0
6581
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...
1
5701
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...
0
3820
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...
0
3845
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1158
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.