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();
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.