다음을 통해 공유


MailTransportBindingElementBase Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Defines the core behavior of the MailTransportBindingElementBase class and provides a base for mail transport binding element derivations.

Namespace:  Microsoft.ServiceModel.Channels.Mail
Assembly:  Microsoft.ServiceModel.Channels.Mail (in Microsoft.ServiceModel.Channels.Mail.dll)

Syntax

'Declaration
Public MustInherit Class MailTransportBindingElementBase _
    Inherits TransportBindingElement
'Usage
Dim instance As MailTransportBindingElementBase
public abstract class MailTransportBindingElementBase : TransportBindingElement
public ref class MailTransportBindingElementBase abstract : public TransportBindingElement
[<AbstractClassAttribute>]
type MailTransportBindingElementBase =  
    class
        inherit TransportBindingElement
    end

Remarks

This class factors out properties that are common to all the mail transport binding elements provided by Windows Communication Foundation (WCF). It handles the translation of the base mail transport settings into run-time manifestations. The class delegates mail transport-specific implementation details to its concrete mail transport binding subclasses, which include the following classes:

You can use the MailTransportBindingElementBase class to create channel factories and channel listeners. When you use this class to create a channel listener for a mail binding, use an overload of the BuildChannelListener<TChannel> method that takes a Uri as one of its arguments. If a Uri is not passed in the call to BuildChannelListener<TChannel>, an ArgumentException is thrown.

A set of binding elements can be used to create a CustomBinding object. In this scenario, use the CustomBinding object to call the BuildChannelFactory<TChannel> and BuildChannelListener<TChannel> methods.

Note

This class is included with the .NET Compact Framework version 3.5, but it requires either the .NET Compact Framework 3.5 or the .NET Framework version 3.0 or later at run time.

Examples

The following example shows how to use the MailTransportBindingElementBase class. It uses a WindowsMobileMailTransportBindingElement and a custom encoding element to create the CustomBinding.

The custom serializer is not specific to the WCF Exchange Server mail transport and is not included in this example.


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();
    }
}

Inheritance Hierarchy

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

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

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

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Version Information

.NET Compact Framework

Supported in: 3.5

See Also

Reference

MailTransportBindingElementBase Members

Microsoft.ServiceModel.Channels.Mail Namespace