共用方式為


MailBindingBase 類別

定義 MailBindingBase 類別 (Class) 的基本行為,並提供郵件繫結衍生的基底。

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

語法

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

備註

MailBindingBase 類別代表預先定義的繫結項目集合,例如編碼項目和傳輸繫結項目。此類別可分解郵件繫結項目的通用屬性。

此類別的預先定義編碼項目為 TextMessageEncodingBindingElement

傳輸繫結項目是由用來執行個體化 MailBindingBase 的具象郵件繫結子類別所決定。這些子類別包括:

WindowsMobileMailBinding 的預先定義傳輸繫結項目為 WindowsMobileMailTransportBindingElementExchangeWebServiceMailBinding 的預先定義傳輸繫結項目為 ExchangeWebServiceMailTransportBindingElement

您可以使用 MailBindingBase 類別來建立通道處理站和通道接聽程式 (Channel Listener)。當您使用此類別建立郵件繫結的通道接聽程式時,請使用以 Uri 當做其中一個引數之 BuildChannelListener 方法的多載。

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

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

範例

下列範例示範如何建構衍生自 MailBindingBase 的物件,並示範如何使用這些物件,在以 WCF Exchange Server Mail Transport 做為基礎的 Windows Communication Foundation (WCF) 應用程式中傳送及接收訊息。

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

Class Program
    Private Shared ServerAddress As New Uri("http://128.128.1.1")
    Private Shared ClientEmailAddress As String = "someone@example.com"
    Private Shared Password As String = "password"

    Private Shared ChannelName As String = "Channel1"
    Private Shared DestinationEmailAddress As String = "someone@fabrikam.com"

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


    Shared Sub Main(ByVal args() As String) 
        ' For applications on the device, use WindowsMobileMailBinding
        ' instead of ExchangeWebServiceMailBinding.
        Dim binding As ExchangeWebServiceMailBinding
        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 message As Message
        Dim str As String

        ' For applications on the device, use WindowsMobileMailBinding.
        binding = New ExchangeWebServiceMailBinding(ServerAddress, New NetworkCredential(ClientEmailAddress, Password))
        bpc = New BindingParameterCollection()

        factory = binding.BuildChannelFactory(Of IOutputChannel)(bpc)
        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 = binding.BuildChannelListener(Of IInputChannel)(MailUriHelper.CreateUri(ChannelName, ""), bpc)
        listener.Open()
        input = listener.AcceptChannel()
        input.Open()

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

        Console.WriteLine("Received message: {0}", str)

        input.Close()
        listener.Close()

        binding.Close()

    End Sub
End Class
class Program
{
    private static Uri ServerAddress = new Uri("http://128.128.1.1");
    private static string ClientEmailAddress = "someone@example.com";
    private static string Password = "password";

    private static string ChannelName = "Channel1";
    private static string DestinationEmailAddress = "someone@fabrikam.com";

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

    static void Main(string[] args)
    {
        // For applications on the device, use WindowsMobileMailBinding
        // instead of ExchangeWebServiceMailBinding.
        ExchangeWebServiceMailBinding binding;
        IChannelFactory<IOutputChannel> factory;
        IChannelListener<IInputChannel> listener;
        IOutputChannel output;
        IInputChannel input;
        BindingParameterCollection bpc;
        Message message;
        string str;

        // For applications on the device, use WindowsMobileMailBinding.
        binding = new ExchangeWebServiceMailBinding(ServerAddress, new NetworkCredential(ClientEmailAddress, Password));
        bpc = new BindingParameterCollection();

        factory = binding.BuildChannelFactory<IOutputChannel>(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 = binding.BuildChannelListener<IInputChannel>(MailUriHelper.CreateUri(ChannelName, ""), bpc);
        listener.Open();
        input = listener.AcceptChannel();
        input.Open();

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

        Console.WriteLine("Received message: {0}", str);

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

        binding.Close();
    }
}

繼承階層架構

System.Object
  System.ServiceModel.Channels.Binding
    Microsoft.ServiceModel.Channels.Mail.MailBindingBase
      Microsoft.ServiceModel.Channels.Mail.WindowsMobile.WindowsMobileMailBinding

執行緒安全

這個型別的任何 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

請參閱

參考

MailBindingBase 成員

Microsoft.ServiceModel.Channels.Mail 命名空間