ServiceContractGenerationContext 类

定义

传递给 GenerateContract(ServiceContractGenerationContext) 方法,以能在生成代码之前对服务协定及其上下文进行修改。Passed to the GenerateContract(ServiceContractGenerationContext) method to enable the modification of a service contract and its context prior to generating code.

public ref class ServiceContractGenerationContext
public class ServiceContractGenerationContext
type ServiceContractGenerationContext = class
Public Class ServiceContractGenerationContext
继承
ServiceContractGenerationContext

示例

下面的示例演示了如何使用传递给 ServiceContractGenerationContext 方法的 IServiceContractGenerationExtension.GenerateContract 对象,来添加从自定义 WSDL 元素提取的代码注释。The following example shows the use of the ServiceContractGenerationContext object passed to the IServiceContractGenerationExtension.GenerateContract method to add code comments extracted from custom WSDL elements.

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

下面的代码示例给出了所生成的代码注释。The following code example shows the resulting code comments.

/// 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 对象可以在生成代码之前修改代码文档对象模型。Use the ServiceContractGenerationContext object passed to the IServiceContractGenerationExtension.GenerateContract method to modify the code document object model prior to the generation of code. 通常,System.ServiceModel.Description.IServiceContractGenerationExtension 接口是在自定义 System.ServiceModel.Description.IWsdlImportExtension 实现上实现的,该实现可用于导入自定义 WSDL 元素,或者在服务或操作级别修改代码。Typically, the System.ServiceModel.Description.IServiceContractGenerationExtension interface is implemented on a custom System.ServiceModel.Description.IWsdlImportExtension implementation that is used to import custom WSDL elements or otherwise modify the code at the service or operation level. 若要在操作级别修改代码,请参见 System.ServiceModel.Description.IOperationContractGenerationExtensionTo modify the code at the operation level, see System.ServiceModel.Description.IOperationContractGenerationExtension.

构造函数

ServiceContractGenerationContext(ServiceContractGenerator, ContractDescription, CodeTypeDeclaration)

使用指定的协定生成器、协定说明和协定代码类型声明初始化 ServiceContractGenerationContext 类的新实例。Initializes a new instance of the ServiceContractGenerationContext class using the specified contract generator, contract description, and contract code type declaration.

ServiceContractGenerationContext(ServiceContractGenerator, ContractDescription, CodeTypeDeclaration, CodeTypeDeclaration)

使用指定的协定生成器、协定说明和协定代码类型声明初始化 ServiceContractGenerationContext 类的新实例。Initializes a new instance of the ServiceContractGenerationContext class using the specified contract generator, contract description, and contract code type declaration.

属性

Contract

获取当前协定的 ContractDescriptionGets the ContractDescription for the current contract.

ContractType

获取当前协定的 CodeTypeDeclarationGets the CodeTypeDeclaration for the current contract.

DuplexCallbackType

获取服务协定上的双向回调协定的 CodeTypeDeclarationGets the CodeTypeDeclaration for the duplex callback contract on the service contract.

Operations

获取表示协定操作的 OperationContractGenerationContext 对象的集合。Gets a collection of OperationContractGenerationContext objects that represent the contract operations.

ServiceContractGenerator

获取要生成协定的 ServiceContractGeneratorGets the ServiceContractGenerator that is to generate the contract.

方法

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于