當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET ITransportHeaders接口代碼示例

本文整理匯總了VB.NET中System.Runtime.Remoting.Channels.ITransportHeaders接口的典型用法代碼示例。如果您正苦於以下問題:VB.NET ITransportHeaders接口的具體用法?VB.NET ITransportHeaders怎麽用?VB.NET ITransportHeaders使用的例子?那麽, 這裏精選的接口代碼示例或許可以為您提供幫助。


在下文中一共展示了ITransportHeaders接口的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: MyITransportHeadersClass

' 導入命名空間
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
開發者ID:VB.NET開發者,項目名稱:System.Runtime.Remoting.Channels,代碼行數:71,代碼來源:ITransportHeaders


注:本文中的System.Runtime.Remoting.Channels.ITransportHeaders接口示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。