Export (0) Print
Expand All

IChannelSender.CreateMessageSink Method

Returns a channel message sink that delivers messages to the specified URL or channel data object.

Namespace: System.Runtime.Remoting.Channels
Assembly: mscorlib (in mscorlib.dll)

IMessageSink CreateMessageSink (
	string url,
	Object remoteChannelData,
	out string objectURI
)
IMessageSink CreateMessageSink (
	String url, 
	Object remoteChannelData, 
	/** @attribute OutAttribute() */ /** @ref */ String objectURI
)
Not applicable.

Parameters

url

The URL to which the new sink will deliver messages. Can be a null reference (Nothing in Visual Basic).

remoteChannelData

The channel data object of the remote host to which the new sink will deliver messages. Can be a null reference (Nothing in Visual Basic).

objectURI

When this method returns, contains a URI of the new channel message sink that delivers messages to the specified URL or channel data object. This parameter is passed uninitialized.

Return Value

A channel message sink that delivers messages to the specified URL or channel data object, or a null reference (Nothing in Visual Basic) if the channel cannot connect to the given endpoint.

Exception typeCondition

SecurityException

The immediate caller does not have infrastructure permission.

The CreateMessageSink method returns a channel message sink that delivers messages to either the specified URL or the channel data object. If the uri parameter is a null reference (Nothing in Visual Basic), the remoteChannelData parameter is used as a target for the sink. Either the url parameter or the remoteChannelData parameter can be a null reference (Nothing in Visual Basic), but not both.

using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Channels.Http;
using System.Security.Permissions;

public class MyClient
{
   [PermissionSet(SecurityAction.LinkDemand)]
   public static void Main()
   {
      try
      {
         // Create the 'IDictionary' to set the server object properties.
         IDictionary myDictionary = new Hashtable();
         myDictionary["name"] = "HttpClientChannel";
         myDictionary["priority"] = 2;
         // Set the properties along with the constructor.
         IChannelSender myIChannelSender = new HttpClientChannel(myDictionary,
                                    new BinaryClientFormatterSinkProvider());
         // Register the server channel.
         ChannelServices.RegisterChannel(myIChannelSender);
         MyHelloServer myHelloServer1 = (MyHelloServer)Activator.GetObject(
                  typeof(MyHelloServer), "http://localhost:8085/SayHello");
         if (myHelloServer1 == null)
         {
            Console.WriteLine("Could not locate server");
         }
         else
         {
            Console.WriteLine(myHelloServer1.myHelloMethod("Client"));
            // Get the name of the channel.
            Console.WriteLine("Channel Name :" + myIChannelSender.ChannelName);
            // Get the channel priority.
            Console.WriteLine("ChannelPriority :" + 
                        myIChannelSender.ChannelPriority.ToString());
            string myString,myObjectURI1;
            Console.WriteLine("Parse :" + 
                myIChannelSender.Parse("http://localhost:8085/SayHello",out myString)
                + myString);
            // Get the channel message sink that delivers message to specified url.
            IMessageSink myIMessageSink = 
                  myIChannelSender.CreateMessageSink(
                  "http://localhost:8085/NewEndPoint", null,out myObjectURI1);
            Console.WriteLine("Channel message sink used :" + myIMessageSink.ToString());
            Console.WriteLine("URI of new channel message sink :" + myObjectURI1);
         }
      }
      catch(Exception ex)
      {
         Console.WriteLine("Following exception is raised on client side : " + ex.Message);
      }
   }
}

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft