Folks, I am trying to use the following code to pass a list of customers in response to a REST based http request. Any idea how I should be using the DataContract & ServiceContract attributes ?
public class Customers : ArrayList
{
public new Customer this[int pIndex]
{
get { return (Customer)base[pIndex]; }
set { base[pIndex] = (Customer)value; }
}
public override int Add(object pObject)
{
return base.Add((Customer )pObject);
}
}
Refer to code, you have to create an Interface class for "Customers". Then add ServiceContract to "Add" interface method. You can refer to below on how to do it. Since the "Add" method will return Int type, it is not required to have DataContract. We use
DataContract if want to return an object which is not premitive type.
And, refer to the "Customers" class, for services, it is advice to not have public property since most of time people don't design the services with state persistant.
No matter how much time you spend on coding. Wish you happy coding.
My Technical Blog
vishatasp.ne...
Member
2 Points
3 Posts
WCF DataContract & ServiceContract
Nov 26, 2012 01:12 AM|LINK
Folks, I am trying to use the following code to pass a list of customers in response to a REST based http request. Any idea how I should be using the DataContract & ServiceContract attributes ?
public class Customers : ArrayList
{
public new Customer this[int pIndex]
{
get { return (Customer)base[pIndex]; }
set { base[pIndex] = (Customer)value; }
}
public override int Add(object pObject)
{
return base.Add((Customer )pObject);
}
}
CruzerB
Contributor
5399 Points
1098 Posts
Re: WCF DataContract & ServiceContract
Nov 26, 2012 01:20 AM|LINK
Hi,
Refer to code, you have to create an Interface class for "Customers". Then add ServiceContract to "Add" interface method. You can refer to below on how to do it. Since the "Add" method will return Int type, it is not required to have DataContract. We use DataContract if want to return an object which is not premitive type.
http://msdn.microsoft.com/en-us/library/ms731835.aspx
And, refer to the "Customers" class, for services, it is advice to not have public property since most of time people don't design the services with state persistant.
My Technical Blog