IChannelSender 介面

定義

提供寄件者通道所需的函式和屬性。

C#
public interface IChannelSender : System.Runtime.Remoting.Channels.IChannel
C#
[System.Runtime.InteropServices.ComVisible(true)]
public interface IChannelSender : System.Runtime.Remoting.Channels.IChannel
衍生
屬性
實作

範例

C#
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Channels.Http;
using System.Security.Permissions;

public class MyClient
{
   public static void Main()
   {
      try
      {
         // Create the 'IDictionary' to set the server object properties.
         IDictionary myDictionary = new Hashtable();
         myDictionary["name"] = "HttpClientChannel";
         myDictionary["priority"] = 2;
         // Set the properties along with the constructor.
         IChannelSender myIChannelSender = new HttpClientChannel(myDictionary,
                                    new BinaryClientFormatterSinkProvider());
         // Register the server channel.
         ChannelServices.RegisterChannel(myIChannelSender);
         MyHelloServer myHelloServer1 = (MyHelloServer)Activator.GetObject(
                  typeof(MyHelloServer), "http://localhost:8085/SayHello");
         if (myHelloServer1 == null)
         {
            Console.WriteLine("Could not locate server");
         }
         else
         {
            Console.WriteLine(myHelloServer1.myHelloMethod("Client"));
            // Get the name of the channel.
            Console.WriteLine("Channel Name :" + myIChannelSender.ChannelName);
            // Get the channel priority.
            Console.WriteLine("ChannelPriority :" +
                        myIChannelSender.ChannelPriority.ToString());
            string myString,myObjectURI1;
            Console.WriteLine("Parse :" +
                myIChannelSender.Parse("http://localhost:8085/SayHello",out myString)
                + myString);
            // Get the channel message sink that delivers message to specified url.
            IMessageSink myIMessageSink =
                  myIChannelSender.CreateMessageSink(
                  "http://localhost:8085/NewEndPoint", null,out myObjectURI1);
            Console.WriteLine("Channel message sink used :" + myIMessageSink.ToString());
            Console.WriteLine("URI of new channel message sink :" + myObjectURI1);
         }
      }
      catch(Exception ex)
      {
         Console.WriteLine("Following exception is raised on client side : " + ex.Message);
      }
   }
}

備註

重要

呼叫實作此介面之類別的方法時,若並用了不信任的資料,會造成安全性上的風險。 呼叫實作此介面之類別的方法時,請一律使用信任的資料。 如需詳細資訊,請參閱 驗證所有輸入

通道的傳送端必須公開 IChannelSender 介面。

屬性

ChannelName

取得通道的名稱。

(繼承來源 IChannel)
ChannelPriority

取得通道的優先權。

(繼承來源 IChannel)

方法

CreateMessageSink(String, Object, String)

傳回通道訊息接收,其傳遞訊息給指定 URL 或通道資料物件。

Parse(String, String)

將物件 URI 傳回為輸出參數,並將目前通道的 URI 值傳回為傳回值。

(繼承來源 IChannel)

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1