ServiceContractGenerator 클래스

정의

ServiceContractGenerator 형식은 ServiceEndpoint 설명 개체에서 서비스 계약 코드와 바인딩 구성을 생성합니다.

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

예제

다음 예제에서는 다운로드한 메타데이터를 ServiceContractGenerator를 사용하여 코드로 변환하는 방법을 보여 줍니다.

  static void GenerateCSCodeForService(EndpointAddress metadataAddress, string outputFile)
  {
MetadataExchangeClient mexClient = new MetadataExchangeClient(metadataAddress);
mexClient.ResolveMetadataReferences = true;
MetadataSet metaDocs = mexClient.GetMetadata();

      WsdlImporter importer = new WsdlImporter(metaDocs);
ServiceContractGenerator generator = new ServiceContractGenerator();

// Add our custom DCAnnotationSurrogate
// to write XSD annotations into the comments.
object dataContractImporter;
XsdDataContractImporter xsdDCImporter;
if (!importer.State.TryGetValue(typeof(XsdDataContractImporter), out dataContractImporter))
{
  Console.WriteLine("Couldn't find the XsdDataContractImporter! Adding custom importer.");
  xsdDCImporter = new XsdDataContractImporter();
  xsdDCImporter.Options = new ImportOptions();
  importer.State.Add(typeof(XsdDataContractImporter), xsdDCImporter);
}
else
{
  xsdDCImporter = (XsdDataContractImporter)dataContractImporter;
  if (xsdDCImporter.Options == null)
  {
    Console.WriteLine("There were no ImportOptions on the importer.");
    xsdDCImporter.Options = new ImportOptions();
  }
}
xsdDCImporter.Options.DataContractSurrogate = new DCAnnotationSurrogate();

// Uncomment the following code if you are going to do your work programmatically rather than add
// the WsdlDocumentationImporters through a configuration file.
/*
// The following code inserts a custom WsdlImporter without removing the other
// importers already in the collection.
System.Collections.Generic.IEnumerable<IWsdlImportExtension> exts = importer.WsdlImportExtensions;
System.Collections.Generic.List<IWsdlImportExtension> newExts
  = new System.Collections.Generic.List<IWsdlImportExtension>();
foreach (IWsdlImportExtension ext in exts)
{
  Console.WriteLine("Default WSDL import extensions: {0}", ext.GetType().Name);
  newExts.Add(ext);
}
newExts.Add(new WsdlDocumentationImporter());
System.Collections.Generic.IEnumerable<IPolicyImportExtension> polExts = importer.PolicyImportExtensions;
importer = new WsdlImporter(metaDocs, polExts, newExts);
*/

System.Collections.ObjectModel.Collection<ContractDescription> contracts
  = importer.ImportAllContracts();
importer.ImportAllEndpoints();
      foreach (ContractDescription contract in contracts)
      {
          generator.GenerateServiceContractType(contract);
      }
if (generator.Errors.Count != 0)
  throw new Exception("There were errors during code compilation.");

// Write the code dom
System.CodeDom.Compiler.CodeGeneratorOptions options
  = new System.CodeDom.Compiler.CodeGeneratorOptions();
      options.BracingStyle = "C";
      System.CodeDom.Compiler.CodeDomProvider codeDomProvider
  = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("C#");
      System.CodeDom.Compiler.IndentedTextWriter textWriter
  = new System.CodeDom.Compiler.IndentedTextWriter(new System.IO.StreamWriter(outputFile));
      codeDomProvider.GenerateCodeFromCompileUnit(
  generator.TargetCompileUnit, textWriter, options
);
      textWriter.Close();
  }

설명

도구를 만들거나 ServiceContractGenerator을 사용하여 기본 계약 생성 프로세스를 수정하려면 System.ServiceModel.Description.IWsdlImportExtension를 사용합니다.

생성자

ServiceContractGenerator()

새로운 ServiceContractGenerator 인스턴스를 사용하여 CodeCompileUnit 클래스의 새 인스턴스를 초기화합니다.

ServiceContractGenerator(CodeCompileUnit)

지정된 ServiceContractGenerator 인스턴스를 사용하여 CodeCompileUnit 클래스의 새 인스턴스를 초기화합니다.

ServiceContractGenerator(CodeCompileUnit, Configuration)

지정된 ServiceContractGeneratorCodeCompileUnit 인스턴스를 사용하여 Configuration 클래스의 새 인스턴스를 초기화합니다.

ServiceContractGenerator(Configuration)

지정된 ServiceContractGenerator 인스턴스를 사용하여 Configuration 클래스의 새 인스턴스를 초기화합니다.

속성

Configuration

생성된 바인딩 구성을 포함하는 Configuration 인스턴스를 가져옵니다.

Errors

서비스 계약 코드 및 엔드포인트 구성을 생성할 때 생성되는 MetadataConversionError 개체 컬렉션을 가져옵니다.

NamespaceMappings

코드를 생성할 때 사용하기 위해 계약 설명 네임스페이스에서 관리 네임스페이스로의 매핑을 가져옵니다.

Options

서비스 계약 코드를 생성하는 옵션을 가져오거나 설정합니다.

ReferencedTypes

계약 설명에서 참조 계약 형식으로 매핑을 가져옵니다.

TargetCompileUnit

서비스 계약 코드를 생성하기 위한 대상 CodeCompileUnit 개체를 가져옵니다.

메서드

Equals(Object)

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

(다음에서 상속됨 Object)
GenerateBinding(Binding, String, String)

지정된 Binding 인스턴스에 대한 바인딩 구성을 생성합니다.

GenerateServiceContractType(ContractDescription)

지정된 ContractDescription 인스턴스에서 서비스 계약 형식을 생성합니다.

GenerateServiceEndpoint(ServiceEndpoint, ChannelEndpointElement)

지정된 ServiceEndpoint 인스턴스에서 서비스 계약 형식과 엔드포인트 구성을 생성합니다.

GetHashCode()

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

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

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

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

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

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

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

(다음에서 상속됨 Object)

적용 대상