ServiceContractGenerator Třída

Definice

Typ ServiceContractGenerator generuje kód kontraktu služby a konfigurace vazeb z ServiceEndpoint popisných objektů.

public ref class ServiceContractGenerator
public class ServiceContractGenerator
type ServiceContractGenerator = class
Public Class ServiceContractGenerator
Dědičnost
ServiceContractGenerator

Příklady

Následující příklad ukazuje použití objektu k převodu ServiceContractGenerator stažených metadat na kód.

  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();
  }

Poznámky

ServiceContractGenerator Použijte k vytvoření nástrojů nebo ke změně výchozího procesu generování kontraktů System.ServiceModel.Description.IWsdlImportExtensionpomocí .

Konstruktory

ServiceContractGenerator()

Inicializuje novou instanci ServiceContractGenerator třídy s novou CodeCompileUnit instancí.

ServiceContractGenerator(CodeCompileUnit)

Inicializuje novou instanci ServiceContractGenerator třídy se zadanou CodeCompileUnit instancí.

ServiceContractGenerator(CodeCompileUnit, Configuration)

Inicializuje novou instanci ServiceContractGenerator třídy se zadanou CodeCompileUnit instancí a zadanou Configuration instancí.

ServiceContractGenerator(Configuration)

Inicializuje novou instanci ServiceContractGenerator třídy se zadanou Configuration instancí.

Vlastnosti

Configuration

Configuration Získá instanci, která obsahuje vygenerované konfigurace vazby.

Errors

Získá kolekci MetadataConversionError objektů vygenerovaných při generování kódu kontraktu služby a konfigurace koncového bodu.

NamespaceMappings

Získá mapování z oboru názvů popisu kontraktu na spravované obory názvů, které se používají při generování kódu.

Options

Získá nebo nastaví možnosti pro generování kódu kontraktu služby.

ReferencedTypes

Získá mapování z popisů kontraktů na odkazované typy kontraktu.

TargetCompileUnit

Získá cílový CodeCompileUnit objekt pro generování kódu kontraktu služby.

Metody

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GenerateBinding(Binding, String, String)

Vygeneruje konfiguraci vazby pro zadanou Binding instanci.

GenerateServiceContractType(ContractDescription)

Generuje typ kontraktu služby ze zadané ContractDescription instance.

GenerateServiceEndpoint(ServiceEndpoint, ChannelEndpointElement)

Vygeneruje typ kontraktu služby a konfiguraci koncového bodu ze zadané ServiceEndpoint instance.

GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetType()

Type Získá z aktuální instance.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro