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.

public interface class IServiceContractGenerationExtension
public interface IServiceContractGenerationExtension
type IServiceContractGenerationExtension = interface
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.

  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.

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.

/// 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;
    }
}

'''From WSDL Documentation:
'''
'''<summary>The string for the Name data member.</summary> 
'''
<System.Runtime.Serialization.DataMemberAttribute()>  _
Public Property Name() As String
    Get
        Return Me.NameField
    End Get
    Set
        Me.NameField = value
    End Set
End Property

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