2016-06-22 7 views
0

メールサーバーの外部から添付ファイルを取得してそこから送信するWebサービスを構築しようとしていますが、エラー:IEnumerableから継承する型は、Add(System.Object)の実装を持たなければなりません。

To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. System.Collections.Specialized.StringDictionary does not implement Add(System.Object). [InvalidOperationException: There was an error reflecting type 'System.Net.Mail.Attachment'.]

私のコードは次のようなものです:

[WebMethod] 
    public String SendMailWithAttachment(string mail_sender, string[] mail_receiver, string mail_subject, string mail_text, Attachment att) 
... 

答えて

0

System.Net.Mail.Attachmentは、XMLにシリアライズされるように設計されていません。添付ファイルを作成するために必要なデータを送信し、Webメソッドの本体で使用する必要があります。たとえば、データを含むバイト配列と添付ファイルの名前を含む文字列を送信します。

[WebMethod] 
public String SendMailWithAttachment(string mail_sender, string[] mail_receiver, string mail_subject, string mail_text, byte[] attachment_data, string attachment_name){ 
    using(var ms = new MemoryStream(attachment_data)){ 
     var attachment = new System.Net.Mail.Attachment(ms,attachment_name); 
     ... 
    } 
} 
+0

ありがとう、これはうまくいきました。 –

関連する問題