IServiceContractGenerationExtension 接口

定义

定义协定生成期间调用的方法,这些方法可用于修改为服务协定生成的代码。

public interface class IServiceContractGenerationExtension
public interface IServiceContractGenerationExtension
type IServiceContractGenerationExtension = interface
Public Interface IServiceContractGenerationExtension

示例

下面的代码示例演示了如何在调用 IServiceContractGenerationExtension 期间向 ContractDescription.Behaviors 属性添加 ImportContract

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

下面的代码示例演示了向为服务协定生成的代码中添加注释的 GenerateContract 的实现。

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

下面的代码示例演示了对服务协定生成的注释。

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

注解

对协定行为(IServiceContractGenerationExtension 类型)实现 System.ServiceModel.Description.IContractBehavior 接口可以使您能够修改协定或终结点编译为代码时生成的代码。

通常,在调用 System.ServiceModel.Description.IWsdlImportExtensionContractDescription.Behaviors 期间,自定义 ImportContract 会向 ImportEndpoint 集合中插入自定义协定行为。

方法

GenerateContract(ServiceContractGenerationContext)

实现此方法可以在开始协定生成过程之前修改代码文档对象模型。

适用于