Langue

ServiceContractAttribute.Namespace Propriété

Définition

Obtient ou définit l’espace de noms de l’élément <portType> dans le langage WSDL (Web Services Description Language).

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

Valeur de propriété

Espace de noms WSDL de l’élément <portType> . La valeur par défaut est "http://tempuri.org".

Exemples

L’exemple de code suivant montre comment utiliser les propriétés et Name les Namespace propriétés de celle-ci ServiceContractAttribute pour définir les valeurs correspondantes dans 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
  }
}

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 utilitaire de métadonnées ServiceModel (Svcutil.exe). Ce client utilise un HelloWorldClient client plutôt qu’un SampleServiceClient client (comme c’est le cas avec l’exemple dans la section Exemple de 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();
    }
  }
}

S’applique à