0

Thank you all in advance for your assistance!

I am creating a .NET WCF web service (C#) for sending emails.. basically a central emailer service that all internal apps can use. my hurdle has been email attachments (1 or more)... I have been looking for the best practices for sending binary data to a WCF web service. The following needs to be considered:

  • all requests to this service will be internal
  • attachments are optional but may contain more than 1
  • for multiple attachments i need to ensure my service doesnt time out

I have read alot about converting binary to a base64 string but alot of the drawbacks with performance (especially with multiple files) scared me from accepting this approach. So i kept searching and found some MTOM topics which are supposed to be more efficient for binary file transfers.

Basically i need guidance on what approach is the best practice for this type of functionality and ideally some sample code to send me on my way.

Thanks again in advance for your time!

4

1 回答 1

1

壁球盒,

我上周刚刚完成了这个练习,关键是流式传输 MTOM 附件,这似乎是发送更大附件的最有效方式。以下是我刚刚挖掘并发现非常有用的一些资源......

MSDN - 如何启用流 式传输http://msdn.microsoft.com/en-us/library/ms789010.aspx

在 WCF 博客 http://nagavitalp.blogspot.com/2011/04/transfer-large-messages-in-wcf-part-1.html中传输大消息

WCF 流:通过 HTTP 上传文件 http://kjellsj.blogspot.com/2007/02/wcf-streaming-upload-files-over-http.html

几个高级键:

您的消息合同需要有一个 Stream body 成员,所有其他元素都需要放在消息头中,例如(对不起 VB.NET,但我目前所在的商店使用它):

<MessageContract()>
Public Class StreamAttachmentRequest

<MessageHeader(MustUnderstand:=True)>
Public Property AttachmentName As String

<MessageBodyMember(Order:=1)>
Public Property Attachment As Stream

End Class

您的绑定必须配置为流式传输 MTOM。喜欢...

   <bindings>

    <basicHttpBinding>

    <binding name="TestCaseBasicBinding"

    messageEncoding="Mtom"

    transferMode="StreamedRequest"

    maxReceivedMessageSize="2147483647"

    closeTimeout="00:30:00"

    openTimeout="00:30:00"

    receiveTimeout="00:30:00"

    sendTimeout="00:30:00">

如果您要传输非常大的附件,您可能需要设置最大请求长度

 <httpRuntime executionTimeout="1800" maxRequestLength="2097151" />

祝你好运,帕特里克

于 2011-08-18T15:21:59.573 回答