This documentation is archived and is not being maintained.

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

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);
      }
   }
}
#using <mscorlib.dll>
#using <System.Runtime.Remoting.dll>
#using <System.dll>
#using <ITransportHeaders_3_Share.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;

__gc class MyITransportHeadersClass : public ITransportHeaders
{
   int myInt;
   DictionaryEntry myDictionaryEntry[];
public:
   MyITransportHeadersClass() {
      myInt = 0;
      myDictionaryEntry = new DictionaryEntry[10];
   }
   // Implement the 'Item' property.
   __property Object* ITransportHeaders::get_Item(Object* myKey)
   {
      if(myKey != 0)
      {
         for(int i = 0; i <= myInt; i++)
            if(myDictionaryEntry[i].Key == myKey)
               return myDictionaryEntry[i].Value;
      }
      return 0;
   }
   __property void ITransportHeaders::set_Item(Object* myKey, Object* value)
   {
      myDictionaryEntry[myInt] = 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();
   }

};

int main()
{
   try
   {
      // Create and register a 'TcpChannel' object.
      TcpChannel* myTcpChannel = new TcpChannel(8085);
      ChannelServices::RegisterChannel(myTcpChannel);
      RemotingConfiguration::RegisterWellKnownServiceType(__typeof(MyHelloServer), S"SayHello",
         WellKnownObjectMode::SingleCall);
      // Create an instance of 'myITransportHeadersObj'.
      MyITransportHeadersClass* myITransportHeadersObj = new MyITransportHeadersClass();
      ITransportHeaders* myITransportHeaders = dynamic_cast<ITransportHeaders*>(myITransportHeadersObj);
      // Add items to the header list.
      myITransportHeaders->Item[S"Header1"] = S"TransportHeader1";
      myITransportHeaders->Item[S"Header2"] = S"TransportHeader2";
      // Get the 'ITranportHeader' item value with key 'Header2'.
      Console::WriteLine(S"ITransport Header item value with key 'Header2' is :{0}", myITransportHeaders->Item[S"Header2"]);
      IEnumerator* myEnumerator = myITransportHeaders->GetEnumerator();
      Console::WriteLine( S"     -KEY-      -VALUE-" );
      while ( myEnumerator->MoveNext() )
      {
         // Display the 'Key' and 'Value' of the current element.
         Object* myEntry = myEnumerator->Current;
         DictionaryEntry myDictionaryEntry = *dynamic_cast<__box DictionaryEntry*>(myEntry);
         Console::WriteLine(S"   {0}:   {1}", myDictionaryEntry.Key, myDictionaryEntry.Value);
      }
      Console::WriteLine(S"Hit <enter> to exit...");
      Console::ReadLine();
   }
   catch(Exception* ex)
   {
      Console::WriteLine(S"The following exception is raised on the server side: {0}", ex->Message);
   }
}

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

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: