IServiceContractGenerationExtension.GenerateContract Yöntem

Tanım

Sözleşme oluşturma işleminden önce kod belgesi nesne modelini değiştirmek için uygulayın.

C#
public void GenerateContract(System.ServiceModel.Description.ServiceContractGenerationContext context);

Parametreler

context
ServiceContractGenerationContext

Kod oluşturmadan önce kod belgesini değiştirmek için kullanılacak bağlam oluşturuldu.

Örnekler

Aşağıdaki kod örneği çağrısı sırasında ImportContractözelliğine ContractDescription.Behaviors nasıl bir IServiceContractGenerationExtension ekleneceğini gösterir.

C#
  public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
  {
Console.Write("ImportContract");
      // Contract Documentation
      if (context.WsdlPortType.Documentation != null)
      {
  context.Contract.Behaviors.Add(new WsdlDocumentationImporter(context.WsdlPortType.Documentation));
      }
      // Operation Documentation
      foreach (Operation operation in context.WsdlPortType.Operations)
      {
          if (operation.Documentation != null)
          {
              OperationDescription operationDescription = context.Contract.Operations.Find(operation.Name);
              if (operationDescription != null)
              {
      operationDescription.Behaviors.Add(new WsdlDocumentationImporter(operation.Documentation));
              }
          }
      }
  }

Aşağıdaki kod örnekleri, bir hizmet sözleşmesi için oluşturulan koda açıklama ekleyen uygulamasını GenerateContract gösterir.

C#
public void GenerateContract(ServiceContractGenerationContext context)
{
  Console.WriteLine("In generate contract.");
  context.ContractType.Comments.AddRange(Formatter.FormatComments(commentText));
}

Aşağıdaki kod örneği, hizmet sözleşmesiyle ilgili oluşturulan açıklamaları gösterir.

C#
/// From WSDL Documentation:
///
/// <summary>The string for the Name data member.</summary>
///
[System.Runtime.Serialization.DataMemberAttribute()]
public string Name
{
    get
    {
        return this.NameField;
    }
    set
    {
        this.NameField = value;
    }
}

Açıklamalar

Sözleşmeyi System.ServiceModel.Description.ServiceContractGenerationContext , işlemleri veya kod oluşturmadan öncekini System.ServiceModel.Description.ServiceContractGenerator değiştirmek için öğesini kullanın.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1