IWsdlImportExtension.ImportContract Method

Called when importing a contract.

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

void ImportContract(
	WsdlImporter importer,
	WsdlContractConversionContext context
)

Parameters

importer
Type: System.ServiceModel.Description.WsdlImporter

The importer.

context
Type: System.ServiceModel.Description.WsdlContractConversionContext

The import context to be modified.

The ImportContract method is called when a contract is being imported. You can modify the contract or insert other exporting behaviors such as System.ServiceModel.Description.IServiceContractGenerationExtension and an System.ServiceModel.Description.IOperationContractGenerationExtension objects to modify the code that is generated for the contract.

The following code example shows the use of IWsdlImportExtension to add an System.ServiceModel.Description.IServiceContractGenerationExtension and an System.ServiceModel.Description.IOperationContractGenerationExtension (the WsdlDocumentationImporter, in this case) to modify generated WCF client code at the interface and operation level.

		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 example shows how to configure the client metadata system to use the custom IWsdlImportExtension from an application configuration file.

<system.serviceModel>
    <client>
      <endpoint 
        address="http://localhost:8000/Fibonacci" 
        binding="wsHttpBinding"
        contract="IFibonacci"
      />
      <metadata>
        <wsdlImporters>
          <extension type="Microsoft.WCF.Documentation.WsdlDocumentationImporter, WsdlDocumentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
        </wsdlImporters>
      </metadata>
    </client>
  </system.serviceModel>

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