ServiceContractAttribute.Name 속성

정의

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

속성 값

String

기본값은 ServiceContractAttribute가 적용되는 클래스 또는 인터페이스의 이름입니다.

예외

값이 null인 경우

값이 빈 문자열인 경우

예제

다음 코드 예제에서는 WSDL에서 Name 해당 값을 설정 하기 위해의 ServiceContractAttribute 속성 및 Namespace 사용 하는 방법을 보여 줍니다.

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

설명

WSDL에서 Name Namespace 요소의 이름과 네임스페이 <portType> 스를 제어하려면 해당 속성과 속성을 사용합니다.

적용 대상