2010-08-07 163 views
0

我正在嘗試將郵件(複雜類型)發送到郵件隊列中。我收到錯誤ETravel.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable。下面是該代碼。將郵件消息發送到郵件隊列時出錯

public void QueueMessage(EmailMessage message) 
     { 
      Message msg = new Message(); 
      msg.Body = message; 
      msg.Recoverable = true; 
      msg.Formatter = new BinaryMessageFormatter(); 
      string queuePath = @".\private$\WebsiteEmails"; 
      //InsureQueueExists(queuePath); 
      MessageQueue msgQ; 
      msgQ = new MessageQueue(queuePath); 
      msgQ.Formatter = new BinaryMessageFormatter(); 
      msgQ.Send((object)msg); 
     } 

複雜類型EmailMessage如下。

public class EmailMessage 
    { 
     public string subject { get; set; } 
     public string message { get; set; } 
     public string from { get; set; } 
     public string to { get; set; } 
    } 

在此先感謝。

我已經安裝了MessageQueue。

O/s:windows xp。
使用的技術:Asp.net mvc。

回答

2

您是否將此課程標記爲[Serializable]?

[Serializable] 
public class EmailMessage 
{ ..... } 

而且 你有沒有方法來序列化 你應該告訴如何使用,你在使用非內置對象

//Deserialization 
public EmailMessage(SerializationInfo info, StreamingContext ctxt) 
{ 


to = (string)info.GetValue("to", typeof(string)); 
from = (String)info.GetValue("from", typeof(string)); 
// add other stuff here 
} 

//Serialization function. 

public void GetObjectData(SerializationInfo info, StreamingContext ctxt) 
{ 

// then you should read the same with "EmployeeId" 

info.AddValue("to", to); 
info.AddValue("from", from); 
} 

編輯您的序列化對象:對不起,我在想的BinaryFormatter不是BinaryMessageFormatter。儘管你仍然可以嘗試一下,看看它是否有效。

關於