Share via


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
[<AbstractClassAttribute>]
type MailTransportBindingElementBase =  
    class
        inherit TransportBindingElement
    end

解説

このクラスでは、Windows Communication Foundation (WCF) によって提供される、すべてのメール トランスポート バインディング要素に共通のプロパティは除外されています。このクラスは、基本のメール トランスポート設定を、実行時にマニフェストに変換する処理を行います。メール トランスポートに固有の実装詳細の処理は、メール トランスポート バインディングの具象サブクラスに任されます。次のようなサブクラスがあります。

MailTransportBindingElementBase クラスを使用して、チャネル ファクトリとチャネル リスナーを作成できます。このクラスを使用してメール バインディングのチャネル リスナーを作成する場合は、引数の 1 つとして BuildChannelListener<TChannel> を受け取る Uri メソッドのオーバーロードを使用します。Uri の呼び出しに BuildChannelListener<TChannel> が渡されない場合は、ArgumentException がスローされます。

一連のバインディング要素を使用して、CustomBinding オブジェクトを作成できます。このシナリオでは、CustomBinding メソッドおよび BuildChannelFactory<TChannel> メソッドの呼び出しに BuildChannelListener<TChannel> オブジェクトを使用します。

注意

このクラスは .NET Compact Framework Version 3.5 に含まれていますが、実行時には .NET Compact Framework 3.5 または .NET Framework Version 3.0 以降が必要です。

MailTransportBindingElementBase クラスを使用する方法の例を次に示します。WindowsMobileMailTransportBindingElement を作成するために、CustomBinding およびカスタムのエンコーディング要素を使用します。

カスタム シリアライザーは WCF Exchange Server のメール トランスポートに固有ではないため、この例に含まれていません。

Class Program
    PrivateShared ChannelName AsString = "Channel1"PrivateShared DestinationEmailAddress AsString = "someone@example.com"PrivateShared serializer AsNew CFMessagingSerializer(GetType(String))


    SharedSub Main(ByVal args() AsString) 
        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 AsStringDim 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(OfString)(serializer)

        MessageBox.Show(str, "Received message")

        input.Close()
        listener.Close()

        mailTransportBindingElement.Close()

    EndSubEndClass
class Program
{
    privatestaticstring ChannelName = "Channel1";
    privatestaticstring DestinationEmailAddress = "someone@example.com";

    privatestatic CFMessagingSerializer serializer = new CFMessagingSerializer(typeof(string));

    staticvoid 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

スレッド セーフ

この型のすべてのパブリック static (Visual Basic では Shared) メンバーは、スレッド セーフです。 インスタンス メンバーの場合は、スレッド セーフであるとは限りません。

プラットフォーム

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

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。 サポートされているバージョンについては、「.NET フレームワークのシステム要件」を参照してください。

バージョン情報

.NET Compact Framework

サポート対象 : 3.5

参照

参照

MailTransportBindingElementBase メンバー

Microsoft.ServiceModel.Channels.Mail 名前空間