Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

IChannelSender::CreateMessageSink Method (String^, Object^, String^%)

 

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)

[SecurityCriticalAttribute]
IMessageSink^ CreateMessageSink(
	String^ url,
	Object^ remoteChannelData,
	[OutAttribute] String^% objectURI
)

Parameters

url
Type: System::String^

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

remoteChannelData
Type: System::Object^

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

objectURI
Type: System::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.

Return Value

Type: System.Runtime.Remoting.Messaging::IMessageSink^

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.

Exception Condition
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 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.

#using <System.Runtime.Remoting.dll>
#using <System.dll>
#using <IChannelSender_Share.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Messaging;
using namespace System::Runtime::Remoting::Channels::Http;
int main()
{
   try
   {

      // Create the 'IDictionary' to set the server object properties.
      IDictionary^ myDictionary = gcnew Hashtable;
      myDictionary->default[ "name" ] = "HttpClientChannel";
      myDictionary->default[ "priority" ] = 2;

      // Set the properties along with the constructor.
      IChannelSender^ myIChannelSender = gcnew HttpClientChannel( myDictionary,gcnew BinaryClientFormatterSinkProvider );

      // Register the server channel.
      ChannelServices::RegisterChannel( myIChannelSender, false );
	  MyHelloServer ^ myHelloServer1 = dynamic_cast<MyHelloServer^>(Activator::GetObject( MyHelloServer::typeid, "http://localhost:8085/SayHello" ));
      if ( myHelloServer1 == nullptr )
      {
         Console::WriteLine( "Could not locate server" );
      }
      else
      {
         Console::WriteLine( myHelloServer1->myHelloMethod( "Client" ) );

         // Get the name of the channel.
         Console::WriteLine( "Channel Name :{0}", myIChannelSender->ChannelName );

         // Get the channel priority.
         Console::WriteLine( "ChannelPriority :{0}", myIChannelSender->ChannelPriority );
         String^ myString;
         String^ myObjectURI1;
         Console::WriteLine( "Parse :{0}{1}", myIChannelSender->Parse( "http://localhost:8085/SayHello",  myString ), myString );

         // Get the channel message sink that delivers message to specified url.
         IMessageSink^ myIMessageSink = myIChannelSender->CreateMessageSink( "http://localhost:8085/NewEndPoint", nullptr,  myObjectURI1 );
         Console::WriteLine( "Channel message sink used :{0}", myIMessageSink );

         Console::WriteLine( "URI of new channel message sink :{0}", myObjectURI1 );
      }
   }
   catch ( Exception^ ex ) 
   {
      Console::WriteLine( "Following exception is raised on client side : {0}", ex->Message );
   }

}

SecurityPermission

for operating with infrastructure code. Demand value: SecurityAction::LinkDemand; Permission value: SecurityPermissionFlag::Infrastructure

.NET Framework
Available since 1.1
Return to top
Show:
© 2017 Microsoft