Reputation: 4753
I am newbie to WCF. Hence, this question. I am in the process of converting an asmx web service to WCF service.
I am having trouble defining data contracts.
I have two operations on my service contract, one returns an array of Customer
, where Customer
is my custom type with some fields.
Here, my question is which needs to declared as data contract.
Is it the Customer
class or Customers
class which contains an array of Customer
or is it both?
Please do suggest
Upvotes: 1
Views: 706
Reputation: 384
Please check this sample code. In following class file i had create data contract for my wcf service. use namespace System.Runtime.Serialization for serialize the data.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
namespace BusinessLogic
{
[DataContract]
[Serializable]
public class POSTheaterListArgs
{
public POSTheaterListArgs()
{
TheaterDates = new List<string>();
}
[DataMember]
public List<string> TheaterDates { get; set; }
[DataMember]
public int TheaterId { get; set; }
[DataMember]
public int NumofScreen { get; set; }
[DataMember]
public int? CompanyId { get; set; }
[DataMember]
public int ChainId { get; set; }
[DataMember]
private int _Number;
public int Number { get { return _Number; } set { _Number = value; } }
private bool _status;
public bool status { get { return _status; } set { _status = value; } }
}
For array data
public POSTheaterListArgs()
{
TheaterDates = new List<string>();
}
[DataMember]
public List<string> TheaterDates { get; set; }
will return you list array structure.
This may help you....
Upvotes: 1
Reputation: 156978
You should read this MSDN article on DataContracts: Using Data Contracts.
In short:
You should define the DataContract
attribute on every class you use in your service that goes across the line, so you would need the attribute on both Customer
and Customers
.
Upvotes: 3