IServiceContractGenerationExtension.GenerateContract 方法

定义

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

public:
 void GenerateContract(System::ServiceModel::Description::ServiceContractGenerationContext ^ context);
public void GenerateContract (System.ServiceModel.Description.ServiceContractGenerationContext context);
abstract member GenerateContract : System.ServiceModel.Description.ServiceContractGenerationContext -> unit
Public Sub GenerateContract (context As ServiceContractGenerationContext)

参数

context
ServiceContractGenerationContext

代码生成要使用的上下文,以在生成之前修改代码文档。

示例

下面的代码示例演示了如何在调用 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

注解

使用 System.ServiceModel.Description.ServiceContractGenerationContext 在代码生成之前修改协定、操作或 System.ServiceModel.Description.ServiceContractGenerator

适用于