Share via


MailBindingBase 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 MailBindingBase class and provides a base for mail binding derivations.

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

Syntax

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

Remarks

The MailBindingBase class represents a predefined collection of binding elements such as an encoding element and a transport binding element. This class factors out properties that are common to all the mail binding elements.

The predefined encoding element for this class is TextMessageEncodingBindingElement.

The transport binding element is determined by the concrete mail binding subclass that is used to instantiate MailBindingBase. These subclasses include the following:

The predefined transport binding element for WindowsMobileMailBinding is WindowsMobileMailTransportBindingElement. The predefined transport binding element for ExchangeWebServiceMailBinding is ExchangeWebServiceMailTransportBindingElement.

You can use the MailBindingBase 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 BuildChannelListener<TChannel> that takes a Uri as one of its arguments.

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 construct objects derived from MailBindingBase. It also shows how to use these objects to send and receive messages in a Windows Communication Foundation (WCF) application based on the WCF Exchange Server mail transport.

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


Class Program
    Private Shared ServerAddress As New Uri("https://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("https://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();
    }
}

Inheritance Hierarchy

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

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

MailBindingBase Members

Microsoft.ServiceModel.Channels.Mail Namespace