2 Questions really, and I'm not sure if I'm doing this right or not...
I want to send back an array of some sort for an Entity object I created. I'm not really sure how to mark it for sending (what attributes are needed or whatever), and I'm not really sure how to send it back (IList, List, Collection, ICollection).
Ideally I'd love to be able to send back an ObservableCollection, but would that work if a client that wants to consume the service isn't in .NET?
[ServiceContract(Namespace = "http://www.tempuri.com/MyService",
ConfigurationName = "IMyService")]
public interface IMyServie
{
[OperationContract(Action = "http://www.tempuri.com/MyService/GetUsers",
ReplyAction = "*")]
[XmlSerializerFormat(SupportFaults = true)]
GetUsersResponse GetUsers(GetUsersRequest request);
}
[MessageContract(IsWrapped = false)]
public sealed class GetUsersRequest
{
public GetUsersRequest() { }
public GetUsersRequest(Int32 record = -1)
{
Record = record;
}
[MessageBodyMember(Namespace = "", Order = 0)]
public Int32 Record { get; private set; }
}
[MessageContract(IsWrapped = false)]
//[ServiceKnownType(??)]
public sealed class GetUsersResponse
{
public GetUsersResponse() { }
public GetUsersResponse(PersonEntity[] entities)
{
Entities = entities;
}
[MessageBodyMember(Namespace = "", Order = 1)]
//[XmlElement(DataType = "??")]
public PersonEntity[] Entities { get; private set; }
//Should this have been some other type of array-type (Collection, List, etc?)
}
//Does this need any attributes besides Serializable?
[Serializable()]
public PersonEntity : AbstractEntity
{
public PersonEntity() { }
public PersonEntity(Int32 id = 0, String fname = "", String lname = "")
{
ID = id;
FirstName = fname;
LastName = lname;
}
public String FirstName { get; set; }
public String LastName { get; set; }
//Functionality (Clone, Clear, Default, Equals, etc) Removed...
}
[Serializable()]
public abstract class AbstractEntity : IEntity
{
public Int32 ID { get; set; }
//Abstracts or Implements some functionality...
}
public interface IEntity
{
//Defines functionality requirements
}