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



{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fprq2\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\lang2052\f0\fs20 Hi Dave,
\par
\par 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?
\par
\par Yes, .NET Framework has some default values for primitive types such as integer, bool, .... For WCF DataContract class, the "DataMemberAttribute" hs some property for control the serlization behavior of default value of field:
\par
\par
\par #Data Member Default Values
\par http://msdn.microsoft.com/en-us/library/aa347792.aspx
\par
\par
\par 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.
\par
\par ==================
\par [DataContract]
\par public class MyTestDC
\par \{
\par private int _count = -1;
\par private bool _valid;
\par
\par [DataMember]
\par public bool Valid
\par \{
\par get \{ return _valid; \}
\par set \{ _valid = value; \}
\par \}
\par
\par [DataMember]
\par public int Count
\par \{
\par get \{ return _count; \}
\par set \{ _count = value; \}
\par \}
\par
\par public MyTestDC()
\par \{
\par _valid = false;
\par \}
\par
\par \}
\par =========================
\par
\par http://blogs.parivedasolutions.com/jtownes/archive/2007/09/11/523.aspx
\par
\par Sincerely,
\par
\par Steven Cheng
\par
\par Microsoft MSDN Online Support Lead
\par
\par
\par 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: msdnmg@xxxxxxxxxxxxxx
\par
\par ==================================================
\par Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notifications.
\par
\par Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support
\par Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support
\par professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations
\par 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/subscriptions/support/default.aspx.
\par ==================================================
\par This posting is provided "AS IS" with no warranties, and confers no rights.
\par
\par
\par
\par \pard\li720 --------------------
\par From: "Dave Burns" <dburns@xxxxxxxxxxxxxxxx>
\par Subject: How to specifiy default values in WCF web services (repost)
\par Date: Tue, 15 Jul 2008 10:12:58 -0500
\par
\par Hello,
\par
\par I am trying to specify a logical default value for a [DataMember] in a WCF
\par Web Service using basicHttpBinding.
\par
\par I realize that the language defaults are:
\par
\par int - 0
\par string - null
\par bool - false
\par enum - ?
\par
\par I tried using OnDeserializing and OnDeserialized events, but when the client
\par doesn't explicitely set the value for an int member, for instance, I keep
\par getting 0. For a bool memeber I get a 'false', and for an enum member it
\par picks some default, but I don't know how it picks it. The only default that
\par I can logically work with is the null for reference types, including
\par strings.
\par
\par The XSD allows you to specify "default=" attribute for a member, but in WCF
\par I don't have control over wsdl/schema generation. So I thought there would
\par be a way to specify a logical default value for a DataMember through an
\par Attribute settings of some sort, but I can't find one.
\par
\par Please help!!!
\par
\par thanks, Dave
\par
\par
\par \pard
\par
\par }

Relevant Pages

  • Re: Problem with winmm.dll under Win2000/XP
    ... Either specify your question clearly, and with adequate information, or ... Control identifier of the desired control. ... This member is used with the ... > without any Problem under Windows 95/98 has a big Problem with Windows ...
    (microsoft.public.vb.winapi)
  • Re: script to change group membership using an input file?
    ... a script can use the NameTranslate object ... IsMember method to check if the user is already a member. ... ' Use the NameTranslate object. ... ' Use Set method to specify DNS domain name. ...
    (microsoft.public.windows.server.scripting)
  • /include/nocopy
    ... Member A comes back up. ... Either I specify all the members ... MOUNT will fail if they are not all available, ... remotely ...
    (comp.os.vms)
  • Re: Removing members from multiple groups in a OU
    ... then bind to each group object and use the Remove ... ' Specify the Distinguished Name of the user. ... ' Filter on groups the user is a member of. ... ' Move to the next record in the recordset. ...
    (microsoft.public.windows.server.scripting)
  • =?ISO-8859-1?Q?Re:_IPL_with_CLPA?=
    ... syntax? ... There is no way to specify a single member on an LPALSTxx input record. ...
    (bit.listserv.ibm-main)

Loading