I’m a newbie to WCF, trying to perform relatively simple task.
I’m trying to return list of objects read from the database but cannot overcome some really annoying exceptions.
The question is very simple? What’s wrong with the picture?
[ServiceContract]
public interface IDBService
{
[OperationContract]
string Ping(string name);
[OperationContract]
InitBDResult InitBD();
}
public InitBDResult InitBD()
{
_dc = new CentralDC();
InitBDResult result = new InitBDResult();
result.ord = _dc.Orders.First();
return result;
}
[DataContract]
public class InitBDResult
{
//[DataMember]
//public List<Order> Orders { get; set; }
[DataMember]
public Order ord { get; set; }
}
Based on what you posted:
Is that method contained in a class that implements the
IDBServiceinterface?? That’s not quite clear from your post….Is the Order class also marked with
[DataContract]and any properties that should be serialized with the[DataMember]attributes??By default, WCF uses the data contract serializer, and it requires the classes to be returned (all of them) to be marked with
[DataContract]and inside those classes, all properties and fields that should be returned in the serialized response to have the[DataMember]attribute.The
[Serializable]attribute doesn’t do anything for the default WCF serialization. Read up on WCF serialization in MSDN magazine – highly recommended!For development, it is often helpful to turn on the exception details from your WCF services, so you get more information about what’s gone wrong. To do this, you need to have a service behavior in your config:
and then apply that behavior to your service in your config:
Then you’ll get the information about details of your exceptions – not just a generic “something went wrong” exception.