Language

ServiceContractAttribute.Namespace プロパティ

定義

Web サービス記述言語 (WSDL) の <portType> 要素の名前空間を取得または設定します。

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

プロパティ値

<portType>要素の WSDL 名前空間。 既定値は "http://tempuri.org" です。

例

次のコード例は、NameのNamespaceプロパティとServiceContractAttributeプロパティを使用して、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
  }
}

次のコード例は、 ServiceModel メタデータ ユーティリティ ツール (Svcutil.exe) を使用して WSDL をインポートした前のサービスの Windows Communication Foundation (WCF) クライアントを示しています。 このクライアントは、HelloWorldClient クライアントではなくSampleServiceClient クライアントを使用します (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();
    }
  }
}

適用対象