IMessageSink Interface
Assembly: mscorlib (in mscorlib.dll)
When a method call is made on the proxy, the remoting infrastructure provides the necessary support for passing the arguments to the actual object across the remoting boundaries, calling the actual object method with the arguments, and returning the results back to the client of the proxy object.
A remote method call is a message that goes from the client end to the server end and possibly back again. As it crosses remoting boundaries on the way, the remote method call passes through a chain of IMessageSink objects. Each sink in the chain receives the message object, performs a specific operation, and delegates to the next sink in the chain. The proxy object contains a reference to the first IMessageSink it needs to use to start off the chain.
For asynchronous calls, at the time of delegation, each sink provides a reply sink (another IMessageSink) that will be called by the next sink when the reply is on its way back.
Different types of sinks perform different operations, depending on the type of message object received. For example, one sink could cause a lock to be taken, another could enforce call security, another could perform flow call control and reliability services, and yet another could transport the call to a different AppDomain, process, or computer. Two or more message sinks in the chain can interact with each other in regard to each specific action.
Notes to Implementers It is important to note that code implementing the current interface must provide implementations for both SyncProcessMessage and AsyncProcessMessage, since synchronous calls can be converted to asynchronous calls and vice versa. Both methods must be implemented, even if the sink does not support asynchronous processing.Imports System 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 'New <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 'MyProxy ' ' 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 'Main End Class 'ProxySample End Namespace 'MyNameSpace
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.