ServiceContractGenerationContext 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
GenerateContract(ServiceContractGenerationContext)传递给该方法以在生成代码之前启用服务协定及其上下文的修改。
public ref class ServiceContractGenerationContext
public class ServiceContractGenerationContext
type ServiceContractGenerationContext = class
Public Class ServiceContractGenerationContext
- 继承
-
ServiceContractGenerationContext
示例
下面的示例演示如何使用 ServiceContractGenerationContext 传递给 IServiceContractGenerationExtension.GenerateContract 方法的对象添加从自定义 WSDL 元素中提取的代码注释。
public void GenerateContract(ServiceContractGenerationContext context)
{
Console.WriteLine("In generate contract.");
context.ContractType.Comments.AddRange(Formatter.FormatComments(commentText));
}
下面的代码示例显示了生成的代码注释。
/// From WSDL Documentation:
///
/// <summary>This contract is a stateless contract that provides a mechanism for
/// computing the nth Fibonacci term.</summary>
///
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://microsoft.wcf.documentation", ConfigurationName="IFibonacci")]
public interface IFibonacci
{
/// From WSDL Documentation:
///
/// <summary>The Compute operation returns the nth Fibonacci number. Because it
/// uses dual recursion it's very inefficient and therefore useful to demonstrate
/// caching.</summary><returns>The nth Fibonacci number.</returns><param
/// name="num">The value to use when computing the Fibonacci number.</param>
///
[System.ServiceModel.OperationContractAttribute(Action="http://microsoft.wcf.documentation/IFibonacci/Compute", ReplyAction="http://microsoft.wcf.documentation/IFibonacci/ComputeResponse")]
int Compute(int num);
/// From WSDL Documentation:
///
/// <summary>The GetPerson operation tests custom WSDL documentation
/// generation.</summary><returns>The Person object to be returned.</returns><param
/// name="FirstParameter">The value for the first parameter.</param><param
/// name="SecondParameter">The value for the second parameter.</param>
///
[System.ServiceModel.OperationContractAttribute(Action="http://microsoft.wcf.documentation/IFibonacci/GetPerson", ReplyAction="http://microsoft.wcf.documentation/IFibonacci/GetPersonResponse")]
Microsoft.WCF.Documentation.Person GetPerson(int FirstParameter, int SecondParameter);
}
'''From WSDL Documentation:
'''
'''<summary>This contract is a stateless contract that provides a mechanism for
'''computing the nth Fibonacci term.</summary>
'''
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0"), _
System.ServiceModel.ServiceContractAttribute([Namespace]:="http://microsoft.wcf.documentation", ConfigurationName:="IFibonacci")> _
Public Interface IFibonacci
'''From WSDL Documentation:
'''
'''<summary>The Compute operation returns the nth Fibonacci number. Because it
'''uses dual recursion it's very inefficient and therefore useful to demonstrate
'''caching.</summary><returns>The nth Fibonacci number.</returns><param
'''name="num">The value to use when computing the Fibonacci number.</param>
'''
<System.ServiceModel.OperationContractAttribute(Action:="http://microsoft.wcf.documentation/IFibonacci/Compute", ReplyAction:="http://microsoft.wcf.documentation/IFibonacci/ComputeResponse")> _
Function Compute(ByVal num As Integer) As Integer
'''From WSDL Documentation:
'''
'''<summary>The GetPerson operation tests custom WSDL documentation
'''generation.</summary><returns>The Person object to be returned.</returns><param
'''name="FirstParameter">The value for the first parameter.</param><param
'''name="SecondParameter">The value for the second parameter.</param>
'''
<System.ServiceModel.OperationContractAttribute(Action:="http://microsoft.wcf.documentation/IFibonacci/GetPerson", ReplyAction:="http://microsoft.wcf.documentation/IFibonacci/GetPersonResponse")> _
Function GetPerson(ByVal FirstParameter As Integer, ByVal SecondParameter As Integer) As Microsoft.WCF.Documentation.Person
End Interface
注解
ServiceContractGenerationContext使用传递给IServiceContractGenerationExtension.GenerateContract方法的对象在生成代码之前修改代码文档对象模型。 通常,该 System.ServiceModel.Description.IServiceContractGenerationExtension 接口是在用于导入自定义 WSDL 元素的自定义 System.ServiceModel.Description.IWsdlImportExtension 实现上实现的,或者在其他服务或操作级别修改代码。 若要在操作级别修改代码,请参阅 System.ServiceModel.Description.IOperationContractGenerationExtension。
构造函数
| 名称 | 说明 |
|---|---|
| ServiceContractGenerationContext(ServiceContractGenerator, ContractDescription, CodeTypeDeclaration, CodeTypeDeclaration) |
使用指定的协定生成器、协定说明和协定代码类型声明初始化类的新实例 ServiceContractGenerationContext 。 |
| ServiceContractGenerationContext(ServiceContractGenerator, ContractDescription, CodeTypeDeclaration) |
使用指定的协定生成器、协定说明和协定代码类型声明初始化类的新实例 ServiceContractGenerationContext 。 |
属性
| 名称 | 说明 |
|---|---|
| Contract |
获取 ContractDescription 当前协定。 |
| ContractType |
获取 CodeTypeDeclaration 当前协定。 |
| DuplexCallbackType |
获取 CodeTypeDeclaration 服务协定上的双工回调协定。 |
| Operations |
获取表示协定操作的对象集合 OperationContractGenerationContext 。 |
| ServiceContractGenerator |
ServiceContractGenerator获取要生成协定的协定。 |
方法
| 名称 | 说明 |
|---|---|
| Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |