IServiceContractGenerationExtension Arabirim

Tanım

Bir hizmet sözleşmesi için oluşturulan kodu değiştirmek için kullanılabilecek sözleşme oluşturma sırasında çağrılan yöntemleri tanımlar.

C#
public interface IServiceContractGenerationExtension

Örnekler

Aşağıdaki kod örneği, çağrısı ImportContractsırasında özelliğine ContractDescription.Behaviors nasıl ekleneceğini IServiceContractGenerationExtension 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şmesinde 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

IServiceContractGenerationExtension Bir sözleşme veya uç nokta kod olarak derlendiğinde oluşturulan kodu değiştirmenize olanak tanımak için bir sözleşme davranışında (System.ServiceModel.Description.IContractBehaviortür) arabirimini uygulayın.

Genellikle, özel System.ServiceModel.Description.IWsdlImportExtension bir özel sözleşme davranışını ContractDescription.Behaviors veya ImportEndpointçağrısı sırasında koleksiyona ImportContract ekler.

Yöntemler

GenerateContract(ServiceContractGenerationContext)

Sözleşme oluşturma işleminden önce kod belgesi nesne modelini değiştirmek için uygulayı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