當前位置: 首頁>>代碼示例>>C#>>正文


C# ITransportHeaders接口代碼示例

本文整理匯總了C#中System.Runtime.Remoting.Channels.ITransportHeaders接口的典型用法代碼示例。如果您正苦於以下問題:C# ITransportHeaders接口的具體用法?C# ITransportHeaders怎麽用?C# ITransportHeaders使用的例子?那麽, 這裏精選的接口代碼示例或許可以為您提供幫助。


ITransportHeaders接口屬於System.Runtime.Remoting.Channels命名空間,在下文中一共展示了ITransportHeaders接口的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: if

//引入命名空間
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

class MyITransportHeadersClass : ITransportHeaders
{
   int myInt = 0;
   DictionaryEntry[] myDictionaryEntry = new DictionaryEntry[10];
   // Implement the 'Item' property.
   object ITransportHeaders.this[object myKey]
   {
      get
      {
         if(myKey != null)
         {
            for(int i = 0; i <= myInt; i++)
               if(myDictionaryEntry[i].Key == myKey)
                  return myDictionaryEntry[i].Value;
         }
         return 0;
      }
      set
      {
         myDictionaryEntry[myInt] = new DictionaryEntry(myKey, value);
         myInt++;
      }
   }
   // Implement the 'GetEnumerator' method.
   IEnumerator ITransportHeaders.GetEnumerator()
   {
      Hashtable myHashtable = new Hashtable();
      for(int j = 0; j < myInt; j++)
         myHashtable.Add(myDictionaryEntry[j].Key, myDictionaryEntry[j].Value);
      return myHashtable.GetEnumerator();
   }

   public static void Main()
   {
      try
      {
         // Create and register a 'TcpChannel' object.
         TcpChannel myTcpChannel = new TcpChannel(8085);
         ChannelServices.RegisterChannel(myTcpChannel);
         RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyHelloServer), "SayHello",
            WellKnownObjectMode.SingleCall);
         // Create an instance of 'myITransportHeadersObj'.
         MyITransportHeadersClass myITransportHeadersObj = new MyITransportHeadersClass();
         ITransportHeaders myITransportHeaders = (ITransportHeaders)myITransportHeadersObj;
         // Add items to the header list.
         myITransportHeaders["Header1"] = "TransportHeader1";
         myITransportHeaders["Header2"] = "TransportHeader2";
         // Get the 'ITranportHeader' item value with key 'Header2'.
         Console.WriteLine("ITransport Header item value with key 'Header2' is :"
            +myITransportHeaders["Header2"]);
         IEnumerator myEnumerator = myITransportHeaders.GetEnumerator();
         Console.WriteLine( "     -KEY-      -VALUE-" );
         while ( myEnumerator.MoveNext() )
         {
            // Display the 'Key' and 'Value' of the current element.
            object myEntry = myEnumerator.Current;
            DictionaryEntry myDictionaryEntry = (DictionaryEntry)myEntry;
            Console.WriteLine("   {0}:   {1}", myDictionaryEntry.Key, myDictionaryEntry.Value);
         }
         Console.WriteLine("Hit <enter> to exit...");
         Console.ReadLine();
      }
      catch(Exception ex)
      {
         Console.WriteLine("The following exception is raised on the server side: " +ex.Message);
      }
   }
}
開發者ID:.NET開發者,項目名稱:System.Runtime.Remoting.Channels,代碼行數:75,代碼來源:ITransportHeaders


注:本文中的System.Runtime.Remoting.Channels.ITransportHeaders接口示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。