ServiceContractGenerator 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이 형식은 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.
생성자
| Name | Description |
|---|---|
| ServiceContractGenerator() |
새 인스턴스를 사용하여 클래스의 ServiceContractGenerator 새 CodeCompileUnit 인스턴스를 초기화합니다. |
| ServiceContractGenerator(CodeCompileUnit, Configuration) |
지정된 인스턴스와 지정된 CodeCompileUnit 인스턴스를 ServiceContractGenerator 사용하여 클래스의 새 인스턴스를 Configuration 초기화합니다. |
| ServiceContractGenerator(CodeCompileUnit) |
지정된 ServiceContractGenerator 인스턴스를 사용하여 클래스의 CodeCompileUnit 새 인스턴스를 초기화합니다. |
| ServiceContractGenerator(Configuration) |
지정된 ServiceContractGenerator 인스턴스를 사용하여 클래스의 Configuration 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| Configuration |
Configuration 생성된 바인딩 구성을 포함하는 인스턴스를 가져옵니다. |
| Errors |
서비스 계약 코드 및 엔드포인트 구성을 생성할 때 생성된 개체의 MetadataConversionError 컬렉션을 가져옵니다. |
| NamespaceMappings |
계약 설명 네임스페이스에서 코드를 생성할 때 사용되는 관리되는 네임스페이스로의 매핑을 가져옵니다. |
| Options |
서비스 계약 코드를 생성하기 위한 옵션을 가져오거나 설정합니다. |
| ReferencedTypes |
계약 설명에서 참조된 계약 형식으로의 매핑을 가져옵니다. |
| TargetCompileUnit |
서비스 계약 코드를 생성하기 위한 대상 CodeCompileUnit 개체를 가져옵니다. |
메서드
| Name | Description |
|---|---|
| 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) |