3

I'd like to setup a WCF service to send emails. The System.Net.MailMessage doesn't seem to be serializable, and cannot be passed in a [DataContract]

The error I receive is

Type 'System.Net.Mail.MailAddress' cannot be serialized. Consider marking it with the DataContractAttribute

Any suggestions?

edosoft
  • 17,121
  • 25
  • 77
  • 111

1 Answers1

3

Whatever you pass to a WCF service needs to be either XML or binary serializable.

A "classic" messaging approach would be:

  1. Create a simple DataContract class that has all the required properties of MailMessage
  2. Prior to calling the service, set all the properties for the MailMessage in a new instance of your DataContract class
  3. Call the service, passing the DataContract
  4. Inside the service, create a new instance of MailMessage and assign the properties into it, then send it
Guy Starbuck
  • 21,603
  • 7
  • 53
  • 64
  • Thanks. What would be the best way to handle Attchements in this way? I'll make a new question. – edosoft Jan 16 '09 at 10:14