IChannelReceiverHook.AddHookChannelUri(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
加入 URI,通道攔截 (Hook) 應該會在其上接聽 (Listen)。
public:
void AddHookChannelUri(System::String ^ channelUri);
public void AddHookChannelUri (string channelUri);
[System.Security.SecurityCritical]
public void AddHookChannelUri (string channelUri);
abstract member AddHookChannelUri : string -> unit
[<System.Security.SecurityCritical>]
abstract member AddHookChannelUri : string -> unit
Public Sub AddHookChannelUri (channelUri As String)
參數
- channelUri
- String
URI,通道攔截應該會在其上接聽。
- 屬性
例外狀況
立即呼叫端沒有基礎結構使用權限。
範例
ref class CustomChannel: public BaseChannelWithProperties, public IChannelReceiverHook, public IChannelReceiver, public IChannel, public IChannelSender
{
public:
virtual void AddHookChannelUri( String^ channelUri )
{
if ( channelUri != nullptr )
{
array<String^>^uris = dataStore->ChannelUris;
// This implementation only allows one URI to be hooked in.
if ( uris == nullptr )
{
array<String^>^newUris = gcnew array<String^>(1);
newUris[ 0 ] = channelUri;
dataStore->ChannelUris = newUris;
wantsToListen = false;
}
else
{
String^ msg = "This channel is already listening for data, and can't be hooked into at this stage.";
throw gcnew System::Runtime::Remoting::RemotingException( msg );
}
}
}
// The rest of CustomChannel's implementation.
class CustomChannel : BaseChannelWithProperties, IChannelReceiverHook,
IChannelReceiver, IChannel, IChannelSender {
public void AddHookChannelUri(string channelUri) {
if (channelUri != null) {
string [] uris = dataStore.ChannelUris;
// This implementation only allows one URI to be hooked in.
if (uris == null) {
string [] newUris = new string[1];
newUris[0] = channelUri;
dataStore.ChannelUris = newUris;
wantsToListen = false;
} else {
string msg = "This channel is already listening for " +
"data, and can't be hooked into at this stage.";
throw new System.Runtime.Remoting.RemotingException(msg);
}
}
}
// The rest of CustomChannel's implementation.
Class CustomChannel
Inherits BaseChannelWithProperties
Implements IChannelReceiverHook, IChannelReceiver, IChannel, IChannelSender
Public Sub AddHookChannelUri(ByVal channelUri As String) _
Implements IChannelReceiverHook.AddHookChannelUri
If Not (channelUri Is Nothing) Then
Dim uris As String() = dataStore.ChannelUris
' This implementation only allows one URI to be hooked in.
If uris Is Nothing Then
Dim newUris(1) As String
newUris(0) = channelUri
dataStore.ChannelUris = newUris
wantsListen = False
Else
Dim msg As String
msg = "This channel is already listening for data, and " + _
"can't be hooked into at this stage."
Throw New System.Runtime.Remoting.RemotingException(msg)
End If
End If
End Sub
' The rest of CustomChannel's implementation.
備註
用戶端程式代碼不應該直接呼叫這個方法。