Cet article a fait l’objet d’une traduction automatique. Pour afficher l’article en anglais, activez la case d’option Anglais. Vous pouvez également afficher le texte anglais dans une fenêtre contextuelle en faisant glisser le pointeur de la souris sur le texte traduit.
Traduction
Anglais

IEndpointBehavior.ApplyDispatchBehavior méthode (ServiceEndpoint, EndpointDispatcher)

 

Date de publication : novembre 2016

Implémente une modification ou une extension du service sur l’intégralité du point de terminaison.

Espace de noms:   System.ServiceModel.Description
Assembly:  System.ServiceModel (dans System.ServiceModel.dll)

void ApplyDispatchBehavior(
	ServiceEndpoint endpoint,
	EndpointDispatcher endpointDispatcher
)

Paramètres

endpoint
Type: System.ServiceModel.Description.ServiceEndpoint

Point de terminaison qui expose le contrat.

endpointDispatcher
Type: System.ServiceModel.Dispatcher.EndpointDispatcher

Répartiteur de points de terminaison à modifier ou étendre.

Implement the M:System.ServiceModel.Description.IEndpointBehavior.ApplyDispatchBehavior(System.ServiceModel.Description.ServiceEndpoint,System.ServiceModel.Dispatcher.EndpointDispatcher) method to view, modify, or extend the service runtime across all messages or for specific operations in an endpoint. For details about what customizations you can do in a service application, see T:System.ServiceModel.Dispatcher.DispatchRuntime and T:System.ServiceModel.Dispatcher.DispatchOperation.

It is recommended that the M:System.ServiceModel.Description.IEndpointBehavior.ApplyDispatchBehavior(System.ServiceModel.Description.ServiceEndpoint,System.ServiceModel.Dispatcher.EndpointDispatcher) method throw a T:System.NotImplementedException exception if the behavior is only intended for use in a client application.

Note that there can be two operations with the same name in the description when using a callback contract (one operation in each direction). If you are iterating through operations, you must correlate the message direction between the endpoint T:System.ServiceModel.Dispatcher.DispatchRuntime and what is returned by the P:System.ServiceModel.Dispatcher.DispatchRuntime.CallbackClientRuntime property.

In addition, because other behaviors may have already added or removed some operations from the runtime, there is no guarantee that there are the same number of operations in description as there are T:System.ServiceModel.Dispatcher.DispatchOperation objects in the P:System.ServiceModel.Dispatcher.DispatchRuntime.Operations property.

The following code example shows the implementation of an endpoint behavior that adds an T:System.ServiceModel.Dispatcher.IDispatchMessageInspector object in a service application. In this case, the EndpointBehaviorMessageInspector class implements T:System.ServiceModel.Dispatcher.IDispatchMessageInspector to inspect the inbound and outbound message, the T:System.ServiceModel.Description.IEndpointBehavior interface to insert the inspector class into the inspection system for all endpoints to which the behavior applies, and the T:System.ServiceModel.Configuration.BehaviorExtensionElement to enable the message inspector behavior using an application configuration file.

The first step is to implement the message inspector.

// IDispatchMessageInspector Members

public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext)
{
  Console.WriteLine("AfterReceiveRequest called.");
  return null;
}

public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
  Console.WriteLine("BeforeSendReply called.");
}

The next code example shows the use of the M:System.ServiceModel.Description.IEndpointBehavior.ApplyDispatchBehavior(System.ServiceModel.Description.ServiceEndpoint,System.ServiceModel.Dispatcher.EndpointDispatcher) method to add the message inspector to the P:System.ServiceModel.Dispatcher.DispatchRuntime.MessageInspectors property.

// IEndpointBehavior Members
public void AddBindingParameters(ServiceEndpoint serviceEndpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
  return;
}

public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior)
{
  behavior.MessageInspectors.Add(new EndpointBehaviorMessageInspector());
}

public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
{
  endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new EndpointBehaviorMessageInspector());
}

public void Validate(ServiceEndpoint serviceEndpoint)
{
  return;
}

The following code example shows the implementation of T:System.ServiceModel.Configuration.BehaviorExtensionElement in order to enable use of the message inspector behavior from a configuration file.

// BehaviorExtensionElement members
public override Type BehaviorType
{
  get { return typeof(EndpointBehaviorMessageInspector); }
}

protected override object CreateBehavior()
{
  return new EndpointBehaviorMessageInspector();
}

Finally, the following configuration file shows how the preceding example can be used from configuration.

Plateforme Windows universelle
Disponible depuis 8
.NET Framework
Disponible depuis 3.0
Bibliothèque de classes portable
Pris en charge dans : plateformes .NET portables
Silverlight
Disponible depuis 4.0
Retour au début
Afficher: