我可以将 System.Net.MailMessage 传递给 WCF 服务吗?

发布于 2024-09-10 10:19:37 字数 236 浏览 2 评论 0原文

我想设置 WCF 服务来发送电子邮件。 System.Net.MailMessage 似乎不可序列化,并且无法在 [DataContract] 中传递

我收到的错误是

输入“System.Net.Mail.MailAddress” 无法序列化。考虑标记 它与 DataContractAttribute

有什么建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剪不断理还乱 2024-09-17 10:19:38

传递给 WCF 服务的任何内容都需要是 XML 或二进制可序列化的。

“经典”消息传递方法是:

  1. 创建一个简单的 DataContract 类,该类具有 MailMessage 的所有必需属性
  2. 在调用服务之前,在 DataContract 类的新实例中设置 MailMessage 的所有属性
  3. 调用服务,传递 DataContract
  4. 在服务内部,创建 MailMessage 的新实例并向其中分配属性,然后发送它

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文