IServiceContractGenerationExtension Interface

Definition

Defines the methods called during contract generation that can be used to modify the generated code for a service contract.

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

Examples

The following code example shows how to add an IServiceContractGenerationExtension to the ContractDescription.Behaviors property during the call to 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));
              }
          }
      }
  }

The following code examples show the implementation of GenerateContract that adds comments to the code generated for a service contract.

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

The following code example shows the generated comments on the service contract.

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

Remarks

Implement the IServiceContractGenerationExtension interface on a contract behavior (a System.ServiceModel.Description.IContractBehavior type) to enable you to modify the code generated when a contract or endpoint is compiled into code.

Typically, a custom System.ServiceModel.Description.IWsdlImportExtension inserts a custom contract behavior into the ContractDescription.Behaviors collection during the call to ImportContract or ImportEndpoint.

Methods

GenerateContract(ServiceContractGenerationContext)

Implement to modify the code document object model prior to the contract generation process.

Applies to