Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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
/** @attribute ComVisibleAttribute(true) */ 
public interface ITransportHeaders
ComVisibleAttribute(true) 
public interface ITransportHeaders

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


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.