次の方法で共有


ITransportHeaders インターフェイス

チャネル シンクで使用されるヘッダーのコレクションを格納します。

この型のすべてのメンバの一覧については、ITransportHeaders メンバ を参照してください。

Public Interface ITransportHeaders
[C#]
public interface ITransportHeaders
[C++]
public __gc __interface ITransportHeaders
[JScript]
public interface ITransportHeaders

ITransportHeaders を実装するクラス

クラス 説明
TransportHeaders チャネル シンクで使用されるヘッダーのコレクションを格納します。

使用例

 

Imports System
Imports System.Collections
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp

Class MyITransportHeadersClass
   Implements ITransportHeaders
   Private myInt As Integer = 0
   Private myDictionaryEntry(9) As DictionaryEntry
   ' Implement the 'Item' property.
   Property ITransportHeaders(myKey As Object) As Object Implements ITransportHeaders.Item
      Get
         If Not (myKey Is Nothing) Then
            Dim i As Integer
            For i = 0 To myInt
               If myDictionaryEntry(i).Key = myKey Then
                  Return myDictionaryEntry(i).Value
               End If
            Next i
         End If
         Return 0
      End Get
      Set
         myDictionaryEntry(myInt) = New DictionaryEntry(myKey, value)
         myInt += 1
      End Set
   End Property

   ' Implement the 'GetEnumerator' method.
   Function GetEnumerator() As IEnumerator  Implements ITransportHeaders.GetEnumerator
      Dim myHashtable As New Hashtable()
      Dim j As Integer
      For j = 0 To myInt - 1
         myHashtable.Add(myDictionaryEntry(j).Key, myDictionaryEntry(j).Value)
      Next j
      Return myHashtable.GetEnumerator()
   End Function 'ITransportHeaders.GetEnumerator

   Public Shared Sub Main()
      Try
         ' Create and register a 'TcpChannel' object.
         Dim myTcpChannel As New TcpChannel(8085)
         ChannelServices.RegisterChannel(myTcpChannel)
         RemotingConfiguration.RegisterWellKnownServiceType(GetType(MyHelloServer), "SayHello", _
                                                         WellKnownObjectMode.SingleCall)
         ' Create an instance of 'myITransportHeadersObj'.
         Dim myITransportHeadersObj As New MyITransportHeadersClass()
         Dim myITransportHeaders As ITransportHeaders = _
                                              CType(myITransportHeadersObj, ITransportHeaders)
         ' 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"))
         Dim myEnumerator As IEnumerator = myITransportHeaders.GetEnumerator()
         Console.WriteLine("     -KEY-      -VALUE-")
         While myEnumerator.MoveNext()
            ' Display the 'Key' and 'Value' of the current element.
            Dim myEntry As Object = myEnumerator.Current
            Dim myDictionaryEntry As DictionaryEntry = CType(myEntry, DictionaryEntry)
            Console.WriteLine("   {0}:   {1}", myDictionaryEntry.Key, myDictionaryEntry.Value)
         End While
         Console.WriteLine("Hit <enter> to exit...")
         Console.ReadLine()
      Catch ex As Exception
         Console.WriteLine("The following exception is raised on the server side: " + ex.Message)
      End Try
   End Sub 'Main
End Class 'MyITransportHeadersClass


[C#] 

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


[C++] 

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

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Runtime.Remoting.Channels

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: Mscorlib (Mscorlib.dll 内)

参照

ITransportHeaders メンバ | System.Runtime.Remoting.Channels 名前空間