本文整理汇总了C#中System.Runtime.Remoting.Channels.ITransportHeaders.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# ITransportHeaders.GetEnumerator方法的具体用法?C# ITransportHeaders.GetEnumerator怎么用?C# ITransportHeaders.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.Remoting.Channels.ITransportHeaders
的用法示例。
在下文中一共展示了ITransportHeaders.GetEnumerator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: if
//引入命名空间
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);
}
}
}