OperationContractAttribute.Name Propriété

Définition

Obtient ou définit le nom de l'opération.

public string Name { get; set; }

Valeur de propriété

Nom de l'opération.

Exceptions

Name a la valeur null.

La valeur est une chaîne vide.

Exemples

L'exemple de code suivant utilise la propriété Name pour déclarer le nom de l'opération comme exposée dans les métadonnées.

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;

namespace Microsoft.WCF.Documentation
{
  [ServiceContract(Namespace="http://Microsoft.WCF.Documentation")]
  public interface ISampleService{

    [OperationContract(
      Action="http://Microsoft.WCF.Documentation/OperationContractMethod",
      Name="OCAMethod",
      ReplyAction="http://Microsoft.WCF.Documentation/ResponseToOCAMethod"
    )]
    string SampleMethod(string msg);

    [OperationContractAttribute(Action = "*")]
    void UnrecognizedMessageHandler(Message msg);
  }

  class SampleService : ISampleService
  {
    public string  SampleMethod(string msg)
    {
      Console.WriteLine("Called with: {0}", msg);
        return "The service greets you: " + msg;
    }

    public void UnrecognizedMessageHandler(Message msg)
    {
      Console.WriteLine("Unrecognized message: " + msg.ToString());
    }
  }
}

Remarques

Utilisez la Name propriété pour remplacer le nom de l’élément <operation> dans WSDL. Le nom d'opération par défaut est celui de la méthode d'implémentation.

S’applique à

Produit Versions
.NET Core 1.0, Core 1.1, 8 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
UWP 10.0