ServiceContractAttribute.Name ServiceContractAttribute.Name ServiceContractAttribute.Name ServiceContractAttribute.Name Property

Définition

Obtient ou définit le nom pour l'élément <portType> dans WSDL (Web Services Description Language).Gets or sets the name for the <portType> element in Web Services Description Language (WSDL).

public:
 property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public string Name { get; set; }
member this.Name : string with get, set
Public Property Name As String

Valeur de propriété

La valeur par défaut est le nom de la classe ou de l'interface à laquelle la ServiceContractAttribute est appliquée.The default value is the name of the class or interface to which the ServiceContractAttribute is applied.

Exceptions

Exemples

L'exemple de code suivant montre comment utiliser les propriétés Name et Namespace de ServiceContractAttribute pour définir les valeurs correspondantes dans WSDL.The following code example shows how to use the Name and Namespace properties of the ServiceContractAttribute to set the corresponding values in WSDL.

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

namespace Microsoft.WCF.Documentation
{
  [ServiceContract(
    Name="HelloWorld",
    Namespace="http://Microsoft.WCF.Documentation"
  )]
  public interface ISampleService{
    [OperationContract]
    string SampleMethod(string msg);
  }

  class SampleService : ISampleService
  {
  #region ISampleService Members

  public string  SampleMethod(string msg)
  {
 	  return "The service greets you: " + msg;
  }

  #endregion
  }
}


Imports System.Collections.Generic
Imports System.ServiceModel
Imports System.Text

Namespace Microsoft.WCF.Documentation
  <ServiceContract(Name:="HelloWorld", Namespace:="http://Microsoft.WCF.Documentation")> _
  Public Interface ISampleService
	<OperationContract> _
	Function SampleMethod(ByVal msg As String) As String
  End Interface

  Friend Class SampleService
	  Implements ISampleService
  #Region "ISampleService Members"

  Public Function SampleMethod(ByVal msg As String) As String Implements ISampleService.SampleMethod
	   Return "The service greets you: " & msg
  End Function

  #End Region
  End Class
End Namespace

L’exemple de code suivant montre un client Windows Communication Foundation (WCF) pour le service précédent qui a importé WSDL à l’aide de l' outil ServiceModel Metadata Utility Tool (Svcutil. exe).The following code example shows an Windows Communication Foundation (WCF) client for the preceding service that imported WSDL using the ServiceModel Metadata Utility Tool (Svcutil.exe). Ce client utilise un client HelloWorldProxy plutôt qu'un client SampleServiceProxy (comme dans le cas de l'exemple de la section Exemple de ServiceContractAttribute).This client uses a HelloWorldProxy client rather than a SampleServiceProxy client (as is the case with the sample in the Example section of ServiceContractAttribute).

using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
 
public class Client
{
  public static void Main()
  {
    // Picks up configuration from the config file.
    HelloWorldClient wcfClient = new HelloWorldClient();
    try
    {
      // Making calls.
      Console.WriteLine("Enter the greeting to send: ");
      string greeting = Console.ReadLine();
      Console.WriteLine("The service responded: " + wcfClient.SampleMethod(greeting));

      // Done with service. 
      wcfClient.Close();
      Console.WriteLine("Done!");
    }
    catch (TimeoutException timeProblem)
    {
      Console.WriteLine("The service operation timed out. " + timeProblem.Message);
      wcfClient.Abort();
    }
    catch (CommunicationException commProblem)
    {
      Console.WriteLine("There was a communication problem. " + commProblem.Message);
      wcfClient.Abort();
    }
    finally
    {
      Console.WriteLine("Press ENTER to exit:");
      Console.ReadLine();
    }
  }
}


Imports System.ServiceModel
Imports System.ServiceModel.Channels

Public Class Client
  Public Shared Sub Main()
	' Picks up configuration from the config file.
	Dim wcfClient As New HelloWorldClient()
	Try
	  ' Making calls.
	  Console.WriteLine("Enter the greeting to send: ")
            Dim greeting = Console.ReadLine()
	  Console.WriteLine("The service responded: " & wcfClient.SampleMethod(greeting))

	  ' Done with service. 
	  wcfClient.Close()
	  Console.WriteLine("Done!")
	Catch timeProblem As TimeoutException
	  Console.WriteLine("The service operation timed out. " & timeProblem.Message)
	  wcfClient.Abort()
	Catch commProblem As CommunicationException
	  Console.WriteLine("There was a communication problem. " & commProblem.Message)
	  wcfClient.Abort()
	Finally
	  Console.WriteLine("Press ENTER to exit:")
	  Console.ReadLine()
	End Try
  End Sub
End Class

Remarques

Utilisez les propriétés Name et Namespace pour contrôler le nom et l'espace de noms de l'élément <portType> dans WSDL.Use the Name and the Namespace properties to control the name and namespace of the <portType> element in WSDL.

S’applique à