IServiceContractGenerationExtension.GenerateContract Method

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

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

'Declaration
Sub GenerateContract ( _
	context As ServiceContractGenerationContext _
)
'Usage
Dim instance As IServiceContractGenerationExtension 
Dim context As ServiceContractGenerationContext

instance.GenerateContract(context)

Parameters

context
Type: System.ServiceModel.Description.ServiceContractGenerationContext

The code generated context to use to modify the code document prior to generation.

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 Property Name() As String 
    Get 
        Return Me.NameField
    End Get 
    Set 
        Me.NameField = value
    End Set 
End Property

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft