IChannelSender.CreateMessageSink(String, Object, String) Method

Definition

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

C#
public System.Runtime.Remoting.Messaging.IMessageSink CreateMessageSink(string url, object remoteChannelData, out string objectURI);
C#
[System.Security.SecurityCritical]
public System.Runtime.Remoting.Messaging.IMessageSink CreateMessageSink(string url, object remoteChannelData, out string objectURI);

Parameters

url
String

The URL to which the new sink will deliver messages. Can be null.

remoteChannelData
Object

The channel data object of the remote host to which the new sink will deliver messages. Can be null.

objectURI
String

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.

Returns

A channel message sink that delivers messages to the specified URL or channel data object, or null if the channel cannot connect to the given endpoint.

Attributes

Exceptions

The immediate caller does not have infrastructure permission.

Examples

C#
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
{
   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);
      }
   }
}

Remarks

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 null, the remoteChannelData parameter is used as a target for the sink. Either the url parameter or the remoteChannelData parameter can be null, but not both.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1