ITransportHeaders.Item[Object] 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 키와 관련된 전송 헤더를 가져오거나 설정합니다.
public:
property System::Object ^ default[System::Object ^] { System::Object ^ get(System::Object ^ key); void set(System::Object ^ key, System::Object ^ value); };
public object this[object key] { get; set; }
public object this[object key] { [System.Security.SecurityCritical] get; [System.Security.SecurityCritical] set; }
member this.Item(obj) : obj with get, set
[<get: System.Security.SecurityCritical>]
[<set: System.Security.SecurityCritical>]
member this.Item(obj) : obj with get, set
Default Public Property Item(key As Object) As Object
매개 변수
- key
- Object
요청된 전송 헤더와 관련된 키입니다.
속성 값
지정된 키와 관련된 전송 헤더입니다.
- 특성
예외
직접 실행 호출자에 인프라 권한이 없는 경우
예제
#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;
ref class MyITransportHeadersClass: public ITransportHeaders
{
private:
int myInt;
array<DictionaryEntry>^myDictionaryEntry;
public:
MyITransportHeadersClass()
{
myInt = 0;
myDictionaryEntry = gcnew array<DictionaryEntry>(10);
}
property Object^ Item [Object^]
{
// Implement the 'Item' property.
virtual Object^ get( Object^ myKey )
{
if ( myKey != nullptr )
{
for ( int i = 0; i <= myInt; i++ )
if ( myDictionaryEntry[ i ].Key == myKey )
return myDictionaryEntry[ i ].Value;
}
return nullptr;
}
virtual void set( Object^ myKey, Object^ value )
{
myDictionaryEntry[ myInt ] = DictionaryEntry(myKey,value);
myInt++;
}
}
// Implement the 'GetEnumerator' method.
virtual IEnumerator^ GetEnumerator()
{
Hashtable^ myHashtable = gcnew 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 = gcnew TcpChannel( 8085 );
ChannelServices::RegisterChannel( myTcpChannel, false );
RemotingConfiguration::RegisterWellKnownServiceType( MyHelloServer::typeid, "SayHello", WellKnownObjectMode::SingleCall );
// Create an instance of 'myITransportHeadersObj'.
MyITransportHeadersClass^ myITransportHeadersObj = gcnew MyITransportHeadersClass;
ITransportHeaders^ myITransportHeaders = dynamic_cast<ITransportHeaders^>(myITransportHeadersObj);
// Add items to the header list.
myITransportHeaders->default[ "Header1" ] = "TransportHeader1";
myITransportHeaders->default[ "Header2" ] = "TransportHeader2";
// Get the 'ITranportHeader' item value with key 'Header2'.
Console::WriteLine( "ITransport Header item value with key 'Header2' is :{0}", myITransportHeaders->default[ "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 = *dynamic_cast<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: {0}", ex->Message );
}
}
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);
}
}
}
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
End Class
설명
저장된 된 헤더가로 설정 된 경우 null
, 키-값 쌍이 제거 됩니다.
적용 대상
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET