I have a web service that queries a db and loads an array of class
objects with data from the dataset.
The class looks like the following:
public class MyData{
public string Data1{get{return mdata1;}}
public string Data2{get{return mdata2;}}
private string mdata1;
private string mdata2;
MyData(DataRow objRow)
{
mdata1 = objRow["data1"].ToString();
mdata2 = objRow["data2"].ToString();
}
}
This class is contained in my web service class so I can create an
instance of the object from the web reference.
My consumer is calling a web method to return an array of MyData
objects as the type from the web service class, like so:
MyService.MyData [] objMyData = null;
MyService.PullMyData(out objMyData);
I then load an ArrayList with this objects, and I have tried several
ways using a loop and adding them individually or passing the class
object array to the array list constructor, to display in a data
grid. I can see the ArrayList holding the data in debug so I know it
has the objects. I can also see the Data1 and Data2 properties of the
objects within the ArrayList object. I format the data in the grid
with a DataGridTableStyle and set the DataSource of the data grid to
the ArrayList holding the MyData objects but no matter what I cannot
get the columns to display in the grid. I then created a new class
called MyData2 in my client with the same Data1 and Data2 properties.
It looks like so:
public class MyData2{
public string Data1{get{return mobjData.Data1;}}
public string Data2{get{return mobjData.Data2;}}
private MyService.MyData mobjData = null;
MyData2(MyService.MyData objData)
{
mobjData = objData;
}
}
I loop through the array received from the web service creating new
MyData2 objects and loading an arraylist like so:
ArrayList objList = new ArrayList();
foreach(MyService.MyData objTemp in objData)
objList.Add(new MyData2(objTemp));
I then do the same with this Arraylist of MyData2 objects of setting
the datasource of the datagrid and formatting the data with
DataGridTableStyle objects and this time the data displays the two
columns with no problem.
Does anyone know why the array of MyData objects from the web service
does not display but the locally defined class objects do display?
What is changing or is different about the objects when they pass
through the web service as opposed to being created locally?
Bryan Phillips - 12 Apr 2007 16:07 GMT
When you use a web service, XML serialization is involved.
I am willing to bet that your Data1 and Data2 properties need set
assessors so that your web reference can deserialize the XML into a
usable class.
--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com
Web Site: http://www.composablesystems.net
> I have a web service that queries a db and loads an array of class
> objects with data from the dataset.
[quoted text clipped - 62 lines]
> What is changing or is different about the objects when they pass
> through the web service as opposed to being created locally?