Class MultiplexingRelayServiceBroker
- Namespace
- Microsoft.ServiceHub.Framework
- Assembly
- Microsoft.ServiceHub.Framework.dll
An IRemoteServiceBroker which proffers all services from another IServiceBroker over an existing Nerdbank.Streams.MultiplexingStream.
public class MultiplexingRelayServiceBroker : IRemoteServiceBroker, IDisposable, IAsyncDisposable
- Inheritance
-
MultiplexingRelayServiceBroker
- Implements
- Inherited Members
Constructors
MultiplexingRelayServiceBroker(IServiceBroker, MultiplexingStream)
Initializes a new instance of the MultiplexingRelayServiceBroker class.
public MultiplexingRelayServiceBroker(IServiceBroker serviceBroker, MultiplexingStream multiplexingStreamWithClient)
Parameters
serviceBrokerIServiceBrokerThe service broker whose services should be multiplexed to the
multiplexingStreamWithClient.multiplexingStreamWithClientMultiplexingStreamThe multiplexing stream to proffer services on.
Properties
Completion
Gets a Task that completes when this instance is disposed of.
public Task Completion { get; }
Property Value
Remarks
This event will occur when the client disconnects from the relay, if the RPC library is configured to dispose target objects at that time.
Methods
CancelServiceRequestAsync(Guid)
Releases resources allocated as a result of a prior call to RequestServiceChannelAsync(ServiceMoniker, ServiceActivationOptions, CancellationToken) when the client cannot or will not complete the connection to the requested service.
public Task CancelServiceRequestAsync(Guid serviceRequestId)
Parameters
serviceRequestIdGuidThe value of RequestId from the connection instructions that will not be followed.
Returns
- Task
A task representing the request to cancel.
ConnectToServerAsync(IServiceBroker, Stream, CancellationToken)
Initializes a new instance of the MultiplexingRelayServiceBroker class and establishes a Nerdbank.Streams.MultiplexingStream protocol with the client over the given stream.
public static Task<MultiplexingRelayServiceBroker> ConnectToServerAsync(IServiceBroker serviceBroker, Stream duplexStreamWithClient, CancellationToken cancellationToken = default)
Parameters
serviceBrokerIServiceBrokerA broker for services to be relayed.
duplexStreamWithClientStreamThe duplex stream over which the client will make RPC calls to the returned IRemoteServiceBroker instance. A multiplexing stream will be established on this stream and the client is expected to accept an offer for a channel with an Empty name. This object is considered "owned" by the returned MultiplexingRelayServiceBroker and will be disposed when the returned value is disposed, or disposed before this method throws.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<MultiplexingRelayServiceBroker>
A MultiplexingRelayServiceBroker that provides access to remote services, all over a multiplexing stream.
Remarks
The RemoteServiceBroker is used as the wire protocol.
Dispose()
[Obsolete("Use DisposeAsync instead.")]
public void Dispose()
Dispose(bool)
Disposes of managed and/or unmanaged resources.
[Obsolete("Override DisposeAsync instead.")]
protected virtual void Dispose(bool disposing)
Parameters
disposingbooltrue to dispose of managed resources as well as unmanaged resources; false to release only unmanaged resources.
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public virtual ValueTask DisposeAsync()
Returns
HandshakeAsync(ServiceBrokerClientMetadata, CancellationToken)
Introduces the client to the server to detail the client's capabilities.
public Task HandshakeAsync(ServiceBrokerClientMetadata clientMetadata, CancellationToken cancellationToken = default)
Parameters
clientMetadataServiceBrokerClientMetadataThe environment, capabilities and attributes of a client of the IRemoteServiceBroker.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task
A task representing this async call.
Exceptions
- NotSupportedException
Thrown when this service broker does not support any of the supported service connection kinds that the client offered in SupportedConnections.
OnAvailabilityChanged(object?, BrokeredServicesChangedEventArgs)
Raises the AvailabilityChanged event.
protected virtual void OnAvailabilityChanged(object? sender, BrokeredServicesChangedEventArgs args)
Parameters
senderobjectThis parameter is ignored. The event will be raised with "this" as the sender.
argsBrokeredServicesChangedEventArgsDetails regarding what changes have occurred.
RequestServiceChannelAsync(ServiceMoniker, ServiceActivationOptions, CancellationToken)
Gets a pipe to a service.
public Task<RemoteServiceConnectionInfo> RequestServiceChannelAsync(ServiceMoniker serviceMoniker, ServiceActivationOptions options = default, CancellationToken cancellationToken = default)
Parameters
serviceMonikerServiceMonikerThe moniker for the service.
optionsServiceActivationOptionsAdditional options that alter how the service may be activated or provide additional data to the service constructor.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<RemoteServiceConnectionInfo>
Instructions for how the client may connect to the service.
Remarks
Upon successful completion, resources may have already been allocated for the anticipated connection. If the connection will not be made (either because the client lost interest or cannot follow the instructions), the client should call CancelServiceRequestAsync(Guid) with the value of RequestId to release the allocated resources.
Events
AvailabilityChanged
Occurs when a service previously queried for since the last AvailabilityChanged event may have changed availability.
public event EventHandler<BrokeredServicesChangedEventArgs>? AvailabilityChanged
Event Type
Remarks
Not all service availability changes result in raising this event. Only those changes that impact services queried for on this IServiceBroker instance will result in an event being raised. Changes already broadcast in a prior event are not included in a subsequent event. The data included in this event may be a superset of the minimum described here.