IOperationContractGenerationExtension Interface

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

Namespace:  System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public interface IOperationContractGenerationExtension

The IOperationContractGenerationExtension type exposes the following members.

  NameDescription
Public methodGenerateOperationImplement to modify the code document object model prior to the contract generation process.
Top

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.

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.

		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#.

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft