Прочитај на енглеском Уреди

Делите путем


IOperationContractGenerationExtension Interface

Definition

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

C#
public interface IOperationContractGenerationExtension

Examples

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.

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.

C#
  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));
              }
          }
      }
  }

Finally, the following code example shows the operation generated in both Visual Basic and C#.

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;
    }
}

Remarks

Implement the IOperationContractGenerationExtension interface on an operation behavior (a System.ServiceModel.Description.IOperationBehavior 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 operation behavior into the OperationDescription.Behaviors collection during the call to IWsdlImportExtension.ImportContract or IWsdlImportExtension.ImportEndpoint.

Methods

GenerateOperation(OperationContractGenerationContext)

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

Applies to

Производ Верзије
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1