共用方式為


MailTransportBindingElementBase 類別

定義 MailTransportBindingElementBase 類別的基本行為,並提供郵件傳輸繫結項目衍生的基底。

命名空間:  Microsoft.ServiceModel.Channels.Mail
組件:  Microsoft.ServiceModel.Channels.Mail (在 Microsoft.ServiceModel.Channels.Mail.dll 中)

語法

'宣告
Public MustInherit Class MailTransportBindingElementBase _
    Inherits TransportBindingElement
'用途
Dim instance As MailTransportBindingElementBase
public abstract class MailTransportBindingElementBase : TransportBindingElement
public ref class MailTransportBindingElementBase abstract : public TransportBindingElement
public abstract class MailTransportBindingElementBase extends TransportBindingElement

備註

此類別可分解 Windows Communication Foundation (WCF) 提供之所有郵件傳輸繫結項目的通用屬性。它會將基本郵件傳輸設定處理成執行階段表現形式。此類別可將郵件傳輸之特定實作 (Implementation) 委派 (Delegate) 給其具象郵件傳輸繫結子類別 (Subclass),包括下列類別:

您可以使用 MailTransportBindingElementBase 類別來建立通道處理站和通道接聽程式 (Listener)。當您使用此類別建立郵件繫結的通道接聽程式時,請使用以 Uri 當做其中一個引數之 BuildChannelListener 方法的多載。如果 BuildChannelListener 的呼叫中未傳遞 Uri,則會擲回 ArgumentException

可用來建立 CustomBinding 物件的一組繫結項目。在這個案例中,請使用 CustomBinding 物件來呼叫 BuildChannelFactoryBuildChannelListener 方法。

Bb339109.alert_note(zh-tw,VS.90).gif注意事項:

此類別隨附於 .NET Compact Framework 3.5 版,但在執行階段則需要 .NET Compact Framework 3.5 或 .NET Framework 3.0 版 (含) 以後版本。

範例

下列範例將示範如何使用 MailTransportBindingElementBase 類別。它會使用 WindowsMobileMailTransportBindingElement 和自訂編碼項目來建立 CustomBinding

自訂序列化程式並非專屬於 WCF Exchange Server Mail Transport,而且未包含在此範例中。

Class Program
    Private Shared ChannelName As String = "Channel1"
    Private Shared DestinationEmailAddress As String = "someone@example.com"

    Private Shared serializer As New CFMessagingSerializer(GetType(String))


    Shared Sub Main(ByVal args() As String) 
        Dim factory As IChannelFactory(Of IOutputChannel)
        Dim listener As IChannelListener(Of IInputChannel)
        Dim output As IOutputChannel
        Dim input As IInputChannel
        Dim bpc As BindingParameterCollection
        Dim mailTransportBindingElement As MailTransportBindingElementBase
        Dim msgEncodingBindingElement As MessageEncodingBindingElement
        Dim message As Message
        Dim str As String
        Dim binding As System.ServiceModel.Channels.Binding

        ' Instantiate a TextMessageEncodingBindingElement or
        ' a custom encoding binding element. If you use a custom encoding
        ' binding element, messages must be sent as attachments.
        msgEncodingBindingElement = New CustomMessageEncodingBindingElement()
        mailTransportBindingElement = New WindowsMobileMailTransportBindingElement()

        mailTransportBindingElement.MessageContainerType = MessageContainerType.Attachment
        ' In this example, set lifetime to 1 day, 10 hours,
        ' 20 minutes, and 30 seconds.
        mailTransportBindingElement.TimeToLive = New TimeSpan(1, 10, 20, 30)
        mailTransportBindingElement.Transport.MaxTotalMessageCacheSize = 1000
        binding = New CustomBinding(msgEncodingBindingElement, mailTransportBindingElement)
        bpc = New BindingParameterCollection()

        factory = binding.BuildChannelFactory(Of IOutputChannel)(bpc)
        listener = binding.BuildChannelListener(Of IInputChannel)(MailUriHelper.CreateUri(ChannelName, ""))

        factory.Open()
        output = factory.CreateChannel(New EndpointAddress(MailUriHelper.Create(ChannelName, DestinationEmailAddress)))
        output.Open()

        message = System.ServiceModel.Channels.Message.CreateMessage(MessageVersion.Default, "urn:Test", "Hello, World!", serializer)
        output.Send(message)

        output.Close()
        factory.Close()

        listener.Open()
        input = listener.AcceptChannel()
        input.Open()

        message = input.Receive()
        str = message.GetBody(Of String)(serializer)

        MessageBox.Show(str, "Received message")

        input.Close()
        listener.Close()

        mailTransportBindingElement.Close()

    End Sub
End Class
class Program
{
    private static string ChannelName = "Channel1";
    private static string DestinationEmailAddress = "someone@example.com";

    private static CFMessagingSerializer serializer = new CFMessagingSerializer(typeof(string));

    static void Main(string[] args)
    {
        IChannelFactory<IOutputChannel> factory;
        IChannelListener<IInputChannel> listener;
        IOutputChannel output;
        IInputChannel input;
        BindingParameterCollection bpc;
        MailTransportBindingElementBase mailTransportBindingElement;
        MessageEncodingBindingElement msgEncodingBindingElement;
        Message message;
        string str;
        System.ServiceModel.Channels.Binding binding;

        // Instantiate a TextMessageEncodingBindingElement or
        // a custom encoding binding element. If you use a custom encoding
        // binding element, messages must be sent as attachments.
        msgEncodingBindingElement = new CustomMessageEncodingBindingElement();
        mailTransportBindingElement = new WindowsMobileMailTransportBindingElement();

        mailTransportBindingElement.MessageContainerType = MessageContainerType.Attachment;
        // In this example, set lifetime to 1 day, 10 hours,
        // 20 minutes, and 30 seconds.
        mailTransportBindingElement.TimeToLive = new TimeSpan(1, 10, 20, 30);
        mailTransportBindingElement.Transport.MaxTotalMessageCacheSize = 1000;

        binding = new CustomBinding(msgEncodingBindingElement, mailTransportBindingElement);
        bpc = new BindingParameterCollection();

        factory = binding.BuildChannelFactory<IOutputChannel>(bpc);
        listener = binding.BuildChannelListener<IInputChannel>(MailUriHelper.CreateUri(ChannelName, ""), bpc);

        factory.Open();
        output = factory.CreateChannel(new EndpointAddress(MailUriHelper.Create(ChannelName, DestinationEmailAddress)));

        output.Open();

        message = Message.CreateMessage(MessageVersion.Default, "urn:Test", "Hello, World!", serializer);
        output.Send(message);

        output.Close();
        factory.Close();

        listener.Open();
        input = listener.AcceptChannel();
        input.Open();

        message = input.Receive();
        str = message.GetBody<string>(serializer);

        MessageBox.Show(str, "Received message");

        input.Close();
        listener.Close();

        mailTransportBindingElement.Close();
    }
}

繼承階層架構

System.Object
  System.ServiceModel.Channels.BindingElement
    System.ServiceModel.Channels.TransportBindingElement
      Microsoft.ServiceModel.Channels.Mail.MailTransportBindingElementBase
        Microsoft.ServiceModel.Channels.Mail.WindowsMobile.WindowsMobileMailTransportBindingElement

執行緒安全

這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

平台

Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Compact Framework

支援版本:3.5

請參閱

參考

MailTransportBindingElementBase 成員

Microsoft.ServiceModel.Channels.Mail 命名空間