本文整理汇总了C#中System.Runtime.Remoting.Channels.ITransportHeaders接口的典型用法代码示例。如果您正苦于以下问题:C# ITransportHeaders接口的具体用法?C# ITransportHeaders怎么用?C# ITransportHeaders使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。
ITransportHeaders接口属于System.Runtime.Remoting.Channels命名空间,在下文中一共展示了ITransportHeaders接口的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);
}
}
}
开发者ID:.NET开发者,项目名称:System.Runtime.Remoting.Channels,代码行数:75,代码来源:ITransportHeaders
注:本文中的System.Runtime.Remoting.Channels.ITransportHeaders接口示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论