Question

I would like to send a list of Appointments through WCF. My Interface looks like this:

[ServiceContract]
    public interface IServices
    {
        [OperationContract]
        string addAppointments(List<Appointment> appointmentList);
    }

If I call my WCF Service I'm always getting the following error:

Type 'Microsoft.Exchange.WebServices.Data.Appointment' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.

My Service currently looks like this:

class Service : IServices 
    {
        public string addAppointments(List<Appointment> appointmentList)
        {
            foreach (Appointment app in appointmentList)
            {
                Console.WriteLine(app.Organizer.Name);
            }
            return "true";
        }
    }
Was it helpful?

Solution

It's not your service that's at fault, it's the class your passing, Appointment. Start by adding [DataContract] to your class. then [DataMember] to each of the properties you'd like to pass.

For example, if you started with:

public class Appointment{
    public DateTime Date { get; set; }
    public string Name { get; set; }
}

You can make it serializable by WCF's DataContractSerializer by adding those attributes:

[DataContract]    
public class Appointment{
    [DataMember]
    public DateTime Date { get; set; }

    [DataMember]
    public string Name { get; set; }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top