다음을 통해 공유


How to: Import Custom WSDL

This topic describes how to import custom WSDL. To handle the custom WSDL, you must implement the IWsdlImportExtension interface.

To import custom WSDL

  1. Implement IWsdlImportExtension. Implement the BeforeImport method to modify the metadata before it is imported. Implement the ImportEndpoint and ImportContract methods to modify contracts and endpoints imported from the metadata. To access the imported contract or endpoint, use the corresponding context object (WsdlContractConversionContext or WsdlEndpointConversionContext):

    public class WsdlDocumentationImporter : IWsdlImportExtension
       {
          public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
    {
            // 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));
    }
    }
    }
    }
    
    public void BeforeImport(ServiceDescriptionCollection wsdlDocuments, XmlSchemaSet xmlSchemas, ICollection<XmlElement> policy) 
            {
                Console.WriteLine("BeforeImport called.");
            }
    
    public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context) 
            {
                Console.WriteLine("ImportEndpoint called.");
            }
       }
    
  2. Configure the client application to use the custom WSDL importer. Note that if you are using Svcutil.exe, you should add this configuration to the configuration file for Svcutil.exe (Svcutil.exe.config):

    <system.serviceModel>
          <client>
            <endpoint 
              address="https://localhost:8000/Fibonacci" 
              binding="wsHttpBinding"
              contract="IFibonacci"
            />
            <metadata>
              <wsdlImporters>
                <extension type="Microsoft.WCF.Documentation.WsdlDocumentationImporter, WsdlDocumentation" />
              </wsdlImporters>
            </metadata>
          </client>
        </system.serviceModel>
    
  3. Create a new WsdlImporter instance (passing in the MetadataSet instance that contains the WSDL documents that you want to import), and call ImportAllContracts:

    WsdlImporter importer = new WsdlImporter(metaDocs);          System.Collections.ObjectModel.Collection<ContractDescription> contracts  = importer.ImportAllContracts();
    

See Also

Concepts

Metadata in Windows Communication Foundation
Exporting and Importing Metadata

Other Resources

Custom WSDL Publication


© 2007 Microsoft Corporation. All rights reserved.
Build Date: 2009-08-07