ContractDescription 클래스

정의

엔드포인트가 외부 대상과 통신하는 내용을 지정하는 WCF(Windows Communication Foundation) 계약에 대해 설명합니다.

public ref class ContractDescription
public class ContractDescription
type ContractDescription = class
Public Class ContractDescription
상속
ContractDescription

예제

다음 예제에서는 개체를 만들거나 검색 ContractDescription 하는 여러 가지 방법을 보여 있습니다. 그런 다음 개체에 저장된 ContractDescription 다양한 정보를 표시합니다.

Uri baseAddress = new Uri("http://localhost:8001/Simple");
ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);

serviceHost.AddServiceEndpoint(
    typeof(ICalculator),
    new WSHttpBinding(),
    "CalculatorServiceObject");

// Enable Mex
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
serviceHost.Description.Behaviors.Add(smb);

serviceHost.Open();

ContractDescription cd0 = new ContractDescription("ICalculator");
ContractDescription cd1 = new ContractDescription("ICalculator", "http://www.tempuri.org");
ContractDescription cd2 = ContractDescription.GetContract(typeof(ICalculator));
CalculatorService calcSvc = new CalculatorService();
ContractDescription cd3 = ContractDescription.GetContract(typeof(ICalculator), calcSvc);
ContractDescription cd4 = ContractDescription.GetContract(typeof(ICalculator), typeof(CalculatorService));
ContractDescription cd = serviceHost.Description.Endpoints[0].Contract;

Console.WriteLine("Displaying information for contract: {0}", cd.Name.ToString());

KeyedByTypeCollection<IContractBehavior> behaviors = cd.Behaviors;
Console.WriteLine("\tDisplay all behaviors:");
foreach (IContractBehavior behavior in behaviors)
{
    Console.WriteLine("\t\t" + behavior.ToString());
}

Type type = cd.CallbackContractType;

string configName = cd.ConfigurationName;
Console.WriteLine("\tConfiguration name: {0}", configName);

Type contractType = cd.ContractType;
Console.WriteLine("\tContract type: {0}", contractType.ToString());

bool hasProtectionLevel = cd.HasProtectionLevel;
if (hasProtectionLevel)
{
    ProtectionLevel protectionLevel = cd.ProtectionLevel;
    Console.WriteLine("\tProtection Level: {0}", protectionLevel.ToString());
}

string name = cd.Name;
Console.WriteLine("\tName: {0}", name);

string namespc = cd.Namespace;
Console.WriteLine("\tNamespace: {0}", namespc);

OperationDescriptionCollection odc = cd.Operations;
Console.WriteLine("\tDisplay Operations:");
foreach (OperationDescription od in odc)
{
    Console.WriteLine("\t\t" + od.Name);
}

SessionMode sm = cd.SessionMode;
Console.WriteLine("\tSessionMode: {0}", sm.ToString());

Collection<ContractDescription> inheretedContracts = cd.GetInheritedContracts();
Console.WriteLine("\tInherited Contracts:");
foreach (ContractDescription contractdescription in inheretedContracts)
{
    Console.WriteLine("\t\t" + contractdescription.Name);
}

Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();

// Close the ServiceHostBase to shutdown the service.
serviceHost.Close();
Dim baseAddress As New Uri("http://localhost:8001/Simple")
Dim serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)

serviceHost.AddServiceEndpoint(GetType(ICalculator), New WSHttpBinding(), "CalculatorServiceObject")

' Enable Mex
Dim smb As New ServiceMetadataBehavior()
smb.HttpGetEnabled = True
serviceHost.Description.Behaviors.Add(smb)

serviceHost.Open()

Dim cd0 As New ContractDescription("ICalculator")
Dim cd1 As New ContractDescription("ICalculator", "http://www.tempuri.org")
Dim cd2 As ContractDescription = ContractDescription.GetContract(GetType(ICalculator))
Dim calcSvc As New CalculatorService()
Dim cd3 As ContractDescription = ContractDescription.GetContract(GetType(ICalculator), calcSvc)
Dim cd4 As ContractDescription = ContractDescription.GetContract(GetType(ICalculator), GetType(CalculatorService))
Dim cd As ContractDescription = serviceHost.Description.Endpoints(0).Contract

Console.WriteLine("Displaying information for contract: {0}", cd.Name.ToString())

Dim behaviors As KeyedByTypeCollection(Of IContractBehavior) = cd.Behaviors
Console.WriteLine(Constants.vbTab & "Display all behaviors:")
For Each behavior As IContractBehavior In behaviors
    Console.WriteLine(Constants.vbTab + Constants.vbTab + CType(behavior, Object).ToString())
Next behavior

Dim type As Type = cd.CallbackContractType

Dim configName As String = cd.ConfigurationName
Console.WriteLine(Constants.vbTab & "Configuration name: {0}", configName)

Dim contractType As Type = cd.ContractType
Console.WriteLine(Constants.vbTab & "Contract type: {0}", contractType.ToString())

Dim hasProtectionLevel As Boolean = cd.HasProtectionLevel
If hasProtectionLevel Then
    Dim protectionLevel As ProtectionLevel = cd.ProtectionLevel
    Console.WriteLine(Constants.vbTab & "Protection Level: {0}", protectionLevel.ToString())
End If


Dim name As String = cd.Name
Console.WriteLine(Constants.vbTab & "Name: {0}", name)

Dim namespc As String = cd.Namespace
Console.WriteLine(Constants.vbTab & "Namespace: {0}", namespc)

Dim odc As OperationDescriptionCollection = cd.Operations
Console.WriteLine(Constants.vbTab & "Display Operations:")
For Each od As OperationDescription In odc
    Console.WriteLine(Constants.vbTab + Constants.vbTab + od.Name)
Next od

Dim sm As SessionMode = cd.SessionMode
Console.WriteLine(Constants.vbTab & "SessionMode: {0}", sm.ToString())

Dim inheretedContracts As Collection(Of ContractDescription) = cd.GetInheritedContracts()
Console.WriteLine(Constants.vbTab & "Inherited Contracts:")
For Each contractdescription As ContractDescription In inheretedContracts
    Console.WriteLine(Constants.vbTab + Constants.vbTab + contractdescription.Name)
Next contractdescription

Console.WriteLine("The service is ready.")
Console.WriteLine("Press <ENTER> to terminate service.")
Console.WriteLine()
Console.ReadLine()

' Close the ServiceHostBase to shutdown the service.
serviceHost.Close()

설명

WCF 계약은 엔드포인트가 외부 세계와 통신하는 작업을 지정하는 작업 컬렉션입니다. 각 작업은 메시지 교환입니다. 예를 들어 요청/응답 메시지 교환은 요청 메시지 및 그와 관련된 응답 메시지로 구성됩니다.

ContractDescription 개체는 WCF 계약 및 해당 작업을 설명하는 데 사용됩니다. ContractDescription내에서 각 계약 작업에는 계약의 일부인 각 작업의 측면을 설명하는 해당 OperationDescription 작업이 있습니다(예: 작업이 단방향인지 요청/회신인지 여부). 각각 OperationDescription 은 을 사용하여 MessageDescriptionCollection작업을 구성하는 메시지에 대해서도 설명합니다. ContractDescription 에는 프로그래밍 모델을 사용하여 계약을 정의하는 인터페이스에 대한 참조가 포함되어 있습니다. 이 인터페이스가 표시 ServiceContractAttribute 되고 엔드포인트 작업에 해당하는 메서드가 .로 OperationContractAttribute표시됩니다.

이중 계약은 다음과 같은 논리 작업 집합을 정의합니다.

  • 서비스에서 클라이언트가 호출할 수 있도록 노출하는 집합입니다.

  • 클라이언트가 호출할 서비스에 대해 노출하는 집합입니다.

이중 계약을 정의하기 위한 프로그래밍 모델은 각 집합을 별도의 인터페이스로 분할하고 각 인터페이스에 특성을 적용하는 것입니다. 이 경우 ContractDescription 하나의 이중 계약으로 그룹화되는 각 인터페이스에 대한 참조를 포함합니다.

바인딩과 마찬가지로 각 계약에는 Name 서비스의 메타데이터에서 고유하게 식별되는 계약이 있습니다 Namespace .

생성자

ContractDescription(String)

지정된 이름을 사용하여 ContractDescription 클래스의 새 인스턴스를 초기화합니다.

ContractDescription(String, String)

네임스페이스로 한정된 이름을 지정하여 ContractDescription 클래스의 새 인스턴스를 초기화합니다.

속성

Behaviors

계약 설명과 관련된 동작을 가져옵니다.

CallbackContractType

계약 설명이 지정하는 콜백 계약의 형식을 가져오거나 설정합니다.

ConfigurationName

계약 설명의 구성 이름을 가져오거나 설정합니다.

ContractBehaviors

계약에 대한 동작의 컬렉션을 가져옵니다.

ContractType

계약 설명이 지정하는 계약 형식을 가져오거나 설정합니다.

HasProtectionLevel

계약에 보호 수준이 설정되어 있는지 여부를 나타내는 값을 가져옵니다.

Name

계약 이름을 가져오거나 설정합니다.

Namespace

계약의 네임스페이스를 가져오거나 설정합니다.

Operations

계약과 연결된 작업 설명 컬렉션을 가져옵니다.

ProtectionLevel

계약과 연결된 보안 보호 수준을 가져오거나 설정합니다.

SessionMode

세션이 계약에 필요한지 여부를 나타내는 값을 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetContract(Type)

지정한 계약 형식에 대한 계약 설명을 반환합니다.

GetContract(Type, Object)

지정한 계약 형식과 서비스 구현에 대한 계약 설명을 반환합니다.

GetContract(Type, Type)

지정한 계약 형식과 서비스 유형에 대한 계약 설명을 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetInheritedContracts()

현재 계약 설명이 상속하는 계약 설명 컬렉션을 반환합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ShouldSerializeProtectionLevel()

ProtectionLevel 속성이 기본값에서 변경되었으며 이를 serialize해야 하는지 여부를 나타내는 값을 반환합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상