本文整理匯總了VB.NET中System.Runtime.Remoting.Messaging.IMessageSink接口的典型用法代碼示例。如果您正苦於以下問題:VB.NET IMessageSink接口的具體用法?VB.NET IMessageSink怎麽用?VB.NET IMessageSink使用的例子?那麽, 這裏精選的接口代碼示例或許可以為您提供幫助。
在下文中一共展示了IMessageSink接口的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: New
' 導入命名空間
Imports System.Collections
Imports System.Threading
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Proxies
Imports System.Runtime.Remoting.Messaging
Imports System.Security.Permissions
Imports Share
Namespace MyNameSpace
Public Class MyProxy
Inherits RealProxy
Private myUrl As String
Private myObjectURI As String
Private myMessageSink As IMessageSink
<PermissionSet(SecurityAction.LinkDemand)> _
Public Sub New(myType As Type, myUrl1 As String)
MyBase.New(myType)
myUrl = myUrl1
Dim myRegisteredChannels As IChannel() = ChannelServices.RegisteredChannels
Dim channel As IChannel
For Each channel In myRegisteredChannels
If TypeOf channel Is IChannelSender Then
Dim myChannelSender As IChannelSender = CType(channel, IChannelSender)
myMessageSink = myChannelSender.CreateMessageSink(myUrl, Nothing, myObjectURI)
If Not (myMessageSink Is Nothing) Then
Exit For
End If
End If
Next channel
If myMessageSink Is Nothing Then
Throw New Exception("A supported channel could not be found for myUrl1:" + myUrl)
End If
End Sub
<SecurityPermission(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.Infrastructure)> _
Public Overrides Function Invoke(ByVal myMesg As IMessage) As IMessage
Console.WriteLine("MyProxy.Invoke Start")
If TypeOf myMesg Is IMethodCallMessage Then
Console.WriteLine("IMethodCallMessage")
End If
If TypeOf myMesg Is IMethodReturnMessage Then
Console.WriteLine("IMethodReturnMessage")
End If
Console.WriteLine("Message Properties")
Dim myDictionary As IDictionary = myMesg.Properties
Dim myEnum As IDictionaryEnumerator = CType(myDictionary.GetEnumerator(), IDictionaryEnumerator)
While myEnum.MoveNext()
Dim myKey As Object = myEnum.Key
Dim myKeyName As String = myKey.ToString()
Dim myValue As Object = myEnum.Value
Console.WriteLine( "{0} : {1}", myKeyName, myEnum.Value)
If myKeyName = "__Args" Then
Dim myArgs As Object() = CType(myValue, Object())
Dim myInt As Integer
For myInt = 0 To myArgs.Length - 1
Console.WriteLine( "arg: {0} myValue: {1}", myInt, myArgs(myInt))
Next myInt
End If
If myKeyName = "__MethodSignature" And Not (myValue Is Nothing) Then
Dim myArgs As Object() = CType(myValue, Object())
Dim myInt As Integer
For myInt = 0 To myArgs.Length - 1
Console.WriteLine("arg: {0} myValue: {1}", myInt, myArgs(myInt))
Next myInt
End If
End While
Console.WriteLine("myUrl1 {0} object URI{1}", myUrl, myObjectURI)
myDictionary("__Uri") = myUrl
Console.WriteLine("URI {0}", myDictionary("__URI"))
Dim myRetMsg As IMessage = myMessageSink.SyncProcessMessage(myMesg)
If TypeOf (myRetMsg) Is IMethodReturnMessage Then
Dim myMethodReturnMessage As IMethodReturnMessage = CType(myRetMsg, IMethodReturnMessage)
End If
Console.WriteLine("MyProxy.Invoke - Finish")
Return myRetMsg
End Function 'Invoke
End Class
'
' Main class that drives the whole sample
'
Public Class ProxySample
<PermissionSet(SecurityAction.LinkDemand)> _
Public Shared Sub Main()
ChannelServices.RegisterChannel(New HttpChannel())
Console.WriteLine("Remoting Sample:")
Console.WriteLine("Generate a new MyProxy using the Type")
Dim myType As Type = GetType(MyHelloService)
Dim myUrl1 As String = "http://localhost/myServiceAccess.soap"
Dim myProxy As New MyProxy(myType, myUrl1)
Console.WriteLine("Obtain the transparent proxy from myProxy")
Dim myService As MyHelloService = CType(myProxy.GetTransparentProxy(), MyHelloService)
Console.WriteLine("Calling the Proxy")
Dim myReturnString As String = myService.myFunction("bill")
Console.WriteLine("Checking result : {0}", myReturnString)
If myReturnString = "Hi there bill, you are using .NET Remoting" Then
Console.WriteLine("myService.HelloMethod PASSED : returned {0}", myReturnString)
Else
Console.WriteLine("myService.HelloMethod FAILED : returned {0}", myReturnString)
End If
End Sub
End Class
End Namespace 'MyNameSpace