IOperationContractGenerationExtension.GenerateOperation(OperationContractGenerationContext) 方法
定义
实现此方法可以在开始协定生成过程之前修改代码文档对象模型。Implement to modify the code document object model prior to the contract generation process.
public:
void GenerateOperation(System::ServiceModel::Description::OperationContractGenerationContext ^ context);
public void GenerateOperation (System.ServiceModel.Description.OperationContractGenerationContext context);
abstract member GenerateOperation : System.ServiceModel.Description.OperationContractGenerationContext -> unit
Public Sub GenerateOperation (context As OperationContractGenerationContext)
参数
包含修改所生成的操作时必须要用到的 System.CodeDom 类型的工作上下文。The working context that contains the System.CodeDom types necessary to modify the generated operation.
示例
下面的代码示例演示了 GenerateOperation 方法的实现,该方法利用 System.CodeDom 命名空间将一个字符串添加到了操作的注释部分中。The following code example shows the implementation of the GenerateOperation method that adds a string to the comments section of the operation using the System.CodeDom namespace.
下面的代码示例演示了在调用 IOperationContractGenerationExtension 期间,实现 OperationDescription.Behaviors 的操作行为是如何插入 IWsdlImportExtension.ImportContract 集合中的。The following code example shows how the operation behavior that implements IOperationContractGenerationExtension is inserted into the OperationDescription.Behaviors collection during the call to IWsdlImportExtension.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));
}
}
}
}
最后,下面的代码示例演示了 Visual Basic 和 C# 中所生成的操作。Finally, the following code example shows the operation generated in both Visual Basic and 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;
}
}
'''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.IWsdlImportExtension 或 OperationDescription.Behaviors 期间,自定义 IWsdlImportExtension.ImportContract 会向 IWsdlImportExtension.ImportEndpoint 集合中插入自定义操作行为。Typically, a custom System.ServiceModel.Description.IWsdlImportExtension inserts a custom operation behavior into the OperationDescription.Behaviors collection during the call to IWsdlImportExtension.ImportContract or IWsdlImportExtension.ImportEndpoint.
对每个协定都调用一次 GenerateOperation。The GenerateOperation method is called once for each contract.