⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wcftransport.cs

📁 微软的行业应用解决方案示例
💻 CS
字号:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;

using Microsoft.ServiceModel.Channels.Mail;
using Microsoft.ServiceModel.Channels.Mail.WindowsMobile;

namespace StoreAndFwdTransport
{
    public class WcfTransport
    {
        WindowsMobileMailBinding _binding;
        IChannelFactory<IOutputChannel> _outputChannelFactory = null;

        public WcfTransport()
        {
            _binding = new WindowsMobileMailBinding();
            _binding.AcceptExistingMessages = true;
        }

        // net.mail://channelName#foo@bar.com
        public IOutputChannel CreateOutputChannel(string channelName, string emailAddress)
        {
            //create output channel factory if one does not already exist
            if (_outputChannelFactory == null)
            {
                BindingParameterCollection emptyParameterCollection = new BindingParameterCollection();
                _outputChannelFactory = _binding.BuildChannelFactory<IOutputChannel>(emptyParameterCollection);
                _outputChannelFactory.Open();
            }

            //create the output channel
            Uri destinationUri = MailUriHelper.CreateUri(channelName, emailAddress);
            EndpointAddress destinationEndpoint = new EndpointAddress(destinationUri);
            IOutputChannel outputChannel = _outputChannelFactory.CreateChannel(destinationEndpoint);

            outputChannel.Open();

            return outputChannel;
        }

        public IInputChannel AcceptInputChannel(string channelName)
        {
            BindingParameterCollection emptyBindParmCollection = new BindingParameterCollection();
            Uri listenerUri = MailUriHelper.CreateUri(channelName, string.Empty);
            IChannelListener<IInputChannel> listener =
                _binding.BuildChannelListener<IInputChannel>(listenerUri, emptyBindParmCollection);
            listener.Open();

            IInputChannel inputChannel = listener.AcceptChannel();
            inputChannel.Open();

            listener.Close();

            return inputChannel;

        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -