Defaulr values in User Defined Objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QWxleA==?=

    #1

    Defaulr values in User Defined Objects

    I have a ws that exposes a class with a user defined type containg a bool, a
    string and an int type properties. I've also set the default values of these
    properties. Unfortunately, when passing the object from a consumer, the
    default properties are not set, exept for the string value.

    The WS is coded as follows:
    public class TestData
    {
    private int _iInt = 10;
    private string _sString = "hi";
    private bool _bBool = true;

    public int IInt
    {
    get { return _iInt; }
    set { _iInt = value; }
    }

    public string SString
    {
    get { return _sString; }
    set { _sString = value; }
    }

    public bool BBool
    {
    get { return _bBool; }
    set { _bBool = value; }
    }
    }

    A web method accepts the object and returns it:
    [WebMethod]
    public TestData ReturnObject(Te stData testInfo)
    {
    TestData returnData = new TestData();
    returnData = testInfo;
    return returnData;
    }

    The consumer instantiates the object and passes it to the method above which
    returns it back:

    [Test]
    public void Test1()
    {
    TestData t = new TestData();
    TestData t2 = _obj.ReturnObje ct(t);
    }

    Looking at t2, I can see the value of SString = "hi", but bBool is false and
    iInt is 0.

    What we're actually trying to do is to add new properties without affecting
    current consumers by defaulting their values. I also tried to set the
    defaultValue attribute but it didn't work either.
  • =?Utf-8?B?QWxleA==?=

    #2
    RE: Defaulr values in User Defined Objects

    I have an update:

    Declaring the object in the WS with the DefaultValue attribute works fine at
    the consumber. Creating the data object has the default values. But when I
    send it to the web method:

    [WebMethod]
    public TestData ReturnObject(Te stData testInfo)
    {
    TestData returnData = new TestData();
    returnData = testInfo;
    return returnData;
    }

    testInfo parameter doesn't have the default values...

    Comment

    • =?Utf-8?B?QWxleA==?=

      #3
      RE: Defaulr values in User Defined Objects

      I had to use both the DefaultValue and setting the default values of the
      private declares.

      Comment

      Working...