Export (0) Print
Expand All

IWsdlImportExtension Interface

Implement and attach to a WsdlImporter object to control how the importer maps Web Services Description Language (WSDL) parts to those of a ServiceDescription object.

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

public interface IWsdlImportExtension

The IWsdlImportExtension type exposes the following members.

  NameDescription
Public methodBeforeImportCalled prior to importing metadata documents.
Public methodImportContractCalled when importing a contract.
Public methodImportEndpointCalled when importing an endpoint.
Top

Implement the IWsdlImportExtension interface to control the mapping between WSDL and ServiceEndpoint and ContractDescription objects, especially when reading custom WSDL extensions to modify your contract or endpoint information. Then attach your custom IWsdlImportExtension object to a WsdlImporter either programmatically or by using an application configuration file. You can also attach your custom IWsdlImportExtension object to the internal WsdlImporter used by the ServiceModel Metadata Utility Tool (Svcutil.exe) using an application configuration file.

The ImportContract method is called to import a contract.

Use the BeforeImport method to modify the metadata that is then imported into ServiceEndpoint and ContractDescription objects.

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

.NET Framework

Supported in: 4.6, 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.

Show:
© 2014 Microsoft