IChannelSender.CreateMessageSink(String, Object, String) Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Retorna um coletor de mensagens de canal que fornece mensagens para a URL especificada ou objeto de dados de canal.
public:
System::Runtime::Remoting::Messaging::IMessageSink ^ CreateMessageSink(System::String ^ url, System::Object ^ remoteChannelData, [Runtime::InteropServices::Out] System::String ^ % objectURI);
public System.Runtime.Remoting.Messaging.IMessageSink CreateMessageSink(string url, object remoteChannelData, out string objectURI);
[System.Security.SecurityCritical]
public System.Runtime.Remoting.Messaging.IMessageSink CreateMessageSink(string url, object remoteChannelData, out string objectURI);
abstract member CreateMessageSink : string * obj * string -> System.Runtime.Remoting.Messaging.IMessageSink
[<System.Security.SecurityCritical>]
abstract member CreateMessageSink : string * obj * string -> System.Runtime.Remoting.Messaging.IMessageSink
Public Function CreateMessageSink (url As String, remoteChannelData As Object, ByRef objectURI As String) As IMessageSink
Parâmetros
- url
- String
A URL para a qual o novo coletor entregará mensagens. Pode ser null.
- remoteChannelData
- Object
O objeto de dados do canal do host remoto ao qual o novo coletor entregará mensagens. Pode ser null.
- objectURI
- String
Quando esse método retorna, contém um URI do novo coletor de mensagens de canal que entrega mensagens para a URL especificada ou objeto de dados de canal. Esse parâmetro é passado sem inicialização.
Retornos
Um coletor de mensagens de canal que fornece mensagens para a URL especificada ou objeto de dados de canal ou null se o canal não pode se conectar ao ponto de extremidade fornecido.
- Atributos
Exceções
O chamador imediato não tem permissão de infraestrutura.
Exemplos
#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 );
}
}
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);
}
}
}
Imports System.Collections
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Messaging
Imports System.Runtime.Remoting.Channels.Http
Imports System.Security.Permissions
Public Class MyClient
<PermissionSet(SecurityAction.LinkDemand)> _
Public Shared Sub Main()
Try
' Create the 'IDictionary' to set the server object properties.
Dim myDictionary As New Hashtable()
myDictionary("name") = "HttpClientChannel"
myDictionary("priority") = 2
' Set the properties along with the constructor.
Dim myIChannelSender As New HttpClientChannel(myDictionary, _
New BinaryClientFormatterSinkProvider())
' Register the server channel.
ChannelServices.RegisterChannel(myIChannelSender)
Dim myHelloServer1 As MyHelloServer = CType(Activator.GetObject(GetType(MyHelloServer), _
"http://localhost:8085/SayHello"), MyHelloServer)
If myHelloServer1 Is Nothing Then
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())
Dim myString As String = ""
Dim myObjectURI1 As String = ""
Console.WriteLine("Parse :" + myIChannelSender.Parse("http://localhost:8085/SayHello", _
myString) + myString)
' Get the channel message sink that delivers message to specified url.
Dim myIMessageSink As IMessageSink = _
myIChannelSender.CreateMessageSink("http://localhost:8085/NewEndPoint", _
Nothing, myObjectURI1)
Console.WriteLine("Channel message sink used :" + CType(myIMessageSink,Object).ToString())
Console.WriteLine("URI of new channel message sink :" + myObjectURI1)
End If
Catch ex As Exception
Console.WriteLine("Following exception is raised on client side : " + ex.Message)
End Try
End Sub
End Class
Comentários
O CreateMessageSink método retorna um coletor de mensagens de canal que entrega mensagens para a URL especificada ou o objeto de dados do canal. Se o uri parâmetro for null, o remoteChannelData parâmetro será usado como um destino para o coletor.
url O parâmetro ou o remoteChannelData parâmetro pode sernull, mas não ambos.