Can I pass a System.Net.MailMessage to a WCF service?

牧云@^-^@ 提交于 2019-12-18 08:56:59

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/447071/can-i-pass-a-system-net-mailmessage-to-a-wcf-service

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!