Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,

I have a doubt.


I have a structure containing an dynamic array.

XML
[DataContract]
public struct Employee
{
    [DataMember]
    public string id;
    [DataMember]
    public string name;

    [DataMember]
    public float[] data;
}


I have a WCF web service which has a function named GetEmployees returns all employee details

XML
[WebGet(UriTemplate = "/Employees")]
List<Employee> GetEmployees();


Service implementation as follows

XML
public List<Employee> GetEmployees()
{
    List<Employee> employees = new List<Employee>{
        new Employee
        {
            id = "1",
            name = "Abc",
            data = new float{1.5f, 3.5f}
        },
        new Employee
        {
            id = "2",
            name = "def" ,
            data = new float{10.5f, 30.5f}
        }
}


And I used this service as follows...

XML
var url = new Uri("http://localhost:34698/RestService.svc/Employees");
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";

var response = (HttpWebResponse)request.GetResponse();

List<Employee> retEmps;
var dataContractSerializer = new DataContractSerializer(typeof(List<Employee>));
 using (var responseStream = response.GetResponseStream())
 {
   retEmps = (List<Employee>)dataContractSerializer.ReadObject(responseStream);
 }
response.Close();


The Id and Name are getting properly, but the data is not getting properly...


Can anyone help me?????
Posted
Comments
Sergey Alexandrovich Kryukov 22-Oct-13 1:20am    
You explained almost everything. What made you to stop here. Next, please. What was wrong, exactly?
—SA
Vineeth.B 22-Oct-13 1:23am    
The Id and Name are getting properly, but the data is not getting properly...

When i debug using VS2010, there are fields like id, name in the returned Employee list. But couldn't get the 'data' float array. Instead there is a field 'ExtensionData' field.
Bernhard Hiller 22-Oct-13 3:33am    
Do you experience the same problems when you use
public List<data>;
instead of
public float[] data;
?
And what about getting one employee only instead of a List of employee (you'll need a different function, do not return a list with one item) - does the data property work there?
Vineeth.B 22-Oct-13 4:18am    
I tried using list instead of float[]. But same problem is there also.

Also tried returning single employee instead of list. Still problem is there..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900