all groups > dotnet web services > february 2007 >
You're in the

dotnet web services

group:

Defaulr values in User Defined Objects



Defaulr values in User Defined Objects Alex
2/21/2007 8:00:41 AM
dotnet web services: 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(TestData 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.ReturnObject(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
RE: Defaulr values in User Defined Objects Alex
2/21/2007 8:02:31 AM
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(TestData testInfo)
{
TestData returnData = new TestData();
returnData = testInfo;
return returnData;
}

RE: Defaulr values in User Defined Objects Alex
2/21/2007 8:37:18 AM
I had to use both the DefaultValue and setting the default values of the
AddThis Social Bookmark Button