Export (0) Print
Expand All

ITransportHeaders Interface

Stores a collection of headers used in the channel sinks.

Namespace:  System.Runtime.Remoting.Channels
Assembly:  mscorlib (in mscorlib.dll)

[ComVisibleAttribute(true)]
public interface ITransportHeaders

The ITransportHeaders type exposes the following members.

  NameDescription
Public propertyItemGets or sets a transport header associated with the given key.
Top

  NameDescription
Public methodGetEnumeratorReturns a IEnumerator that iterates over all entries in the ITransportHeaders object.
Top


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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft