发送带有空流(Stream.null)的电子邮件作为附件时,WCF电子邮件Web服务错误异常 [英] WCF email web service error exception when sending email with null stream (Stream.null) for attachment

查看:120
本文介绍了发送带有空流(Stream.null)的电子邮件作为附件时,WCF电子邮件Web服务错误异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,当我使用下面的代码从另一个c#应用程序调用我的wcf服务时,我获得了发送所需电子邮件的电子邮件服务(它可以工作),但是带有下面代码的调用应用程序捕获了错误(通过try {} Catch {})指示以下内容:值不能为空.参数名称:内部错误:在http://tempuri.org/IEmailService/SendEmailResponse中,MessageContract的实例不能为空.".仅当调用应用程序发送不带附件的电子邮件时才会发生此错误,但是,当发送带附件的电子邮件时,不会出现没有错误.不确定如何解决此问题.

Issue I am having is when I call my wcf service from another c# app using the code below, I get the email service to send the needed email (it works), but the calling application with the code below captures an error (via try{}Catch{}) indicating the following: "Value cannot be null. Parameter name: Internal Error: The instance of the MessageContract cannot be null in http://tempuri.org/IEmailService/SendEmailResponse.". This error happens only when the calling application is sending an email without attachment, when sending an email with attachment though, there would be no error. Not sure how to resolve this issue.

EmailServiceClient proxy = new EmailServiceClient();
           EmailMessage emailMsg = new EmailMessage();

           emailMsg.EmailParamHeaders = new DataContracts.Email();

           emailMsg.EmailParamHeaders.To = new string[1];
           emailMsg.EmailParamHeaders.CC = new string[1];

           emailMsg.EmailParamHeaders.From = tmpactivityDetails.FromEmailAddress;
           emailMsg.EmailParamHeaders.To[0] = tmpactivityDetails.ToEmailAddress;
           emailMsg.EmailParamHeaders.CC[0] = "";

           emailMsg.EmailParamHeaders.Subject = tmpactivityDetails.EmailSubject;
           emailMsg.EmailParamHeaders.Message = tmpactivityDetails.EmailBody;

           emailMsg.EmailParamHeaders.AttachmentFileName = null;

           proxy.SendEmail(emailMsg.EmailParamHeaders, Stream.Null);
           proxy.Close();



以下是我的wcf服务应用程序中的一些代码,向您显示了EmailMessage合同:



Here below is some code from my wcf service app showing you the EmailMessage contract:

namespace MessageContract
{


    [MessageContract]
    public class EmailMessage
    {
        [MessageHeader(MustUnderstand = true)]
        DataContracts.Email EmailParamHeaders;
        [MessageBodyMember(Order = 1)]
        public Stream EmailAttachment;
    }

    [MessageContract]
    public class ReturnValues   //Note: returning an array of error codes-if any
    {
        public string[] returnValues { get; set; }
    }
}



这是电子邮件合同:



Here is the email contract:

namespace DataContracts
{
    [DataContract(Name="Email")]
    public class Email
    {

        [DataMember(Order = 0, IsRequired =  false)]
        public string From { get; set; }
        [DataMember(Order = 1, IsRequired = true)]
        public string[] To { get; set; }
        [DataMember(Order = 2, IsRequired = false)]
        public string[] CC { get; set; }
        [DataMember(Order = 3, IsRequired = true)]
        public string Subject { get; set; }
        [DataMember(Order = 4, IsRequired = true)]
        public string Message { get; set; }
        [DataMember(Order = 5, IsRequired = false)]
        public string AttachmentFileName { get; set; }
    }
}



让我知道您是否需要更多信息,谢谢.



Let me know if u need more information, thanks.

推荐答案

tempuri表示TEMPoraryURI.您应该更改它.

我认为您的合同需要说明EmailAttachment是可选的,这就是为什么它爆炸了.
tempuri means TEMPoraryURI. You should change it.

I think your contract needs to state that the EmailAttachment is optional, that''s why it''s blowing up.


已解决的问题是由跟踪空文件名引起的(无关) ).
Resolved issue which was caused by trace logging of null file name (unrelated).


这篇关于发送带有空流(Stream.null)的电子邮件作为附件时,WCF电子邮件Web服务错误异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆