ServiceContractAttribute.Name プロパティ

定義

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

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

プロパティ値

既定値は ServiceContractAttribute が適用されたクラスまたはインターフェイスの名前です。

例外

値が null です。

値が空の文字列です。

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

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

注釈

Nameプロパティと プロパティをNamespace使用して、WSDL 内の要素の名前と名前空間を<portType>制御します。

適用対象