IWsdlImportExtension 介面

定義

請實作並附加至 WsdlImporter 物件,以控制匯入工具如何將 Web 服務描述語言 (WSDL) 部分對應至 ServiceDescription 物件的部分。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.

public interface class IWsdlImportExtension
public interface IWsdlImportExtension
type IWsdlImportExtension = interface
Public Interface IWsdlImportExtension
衍生

範例

下列IWsdlImportExtension程式碼範例示範如何使用來System.ServiceModel.Description.IServiceContractGenerationExtension加入和System.ServiceModel.Description.IOperationContractGenerationExtension ( WsdlDocumentationImporter在此案例中為), 以便在介面和作業層級上修改產生的 WCF 用戶端程式代碼。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));
              }
          }
      }
  }

下列程式碼範例會示範如何設定用戶端中繼資料系統,以便從應用程式組態檔使用自訂 IWsdlImportExtensionThe 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>

備註

實作 IWsdlImportExtension 介面,以控制 WSDL 和 ServiceEndpointContractDescription 物件之間的對應,特別是當讀取自訂 WSDL 延伸以修改您的合約或端點資訊時。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. 然後以程式設計的方法或使用應用程式組態檔,將您的自訂 IWsdlImportExtension 物件附加至 WsdlImporterThen attach your custom IWsdlImportExtension object to a WsdlImporter either programmatically or by using an application configuration file. 您也可以使用應用程式IWsdlImportExtension設定檔, 將WsdlImporter自訂物件附加至system.servicemodel 中繼資料公用程式工具 (Svcutil)所使用的內部。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.

會呼叫 ImportContract 方法來匯入合約。The ImportContract method is called to import a contract.

您可以使用 BeforeImport 方法來修改接著匯入至 ServiceEndpointContractDescription 物件的中繼資料。Use the BeforeImport method to modify the metadata that is then imported into ServiceEndpoint and ContractDescription objects.

方法

BeforeImport(ServiceDescriptionCollection, XmlSchemaSet, ICollection<XmlElement>)

在匯入中繼資料文件之前呼叫。Called prior to importing metadata documents.

ImportContract(WsdlImporter, WsdlContractConversionContext)

在匯入合約時呼叫。Called when importing a contract.

ImportEndpoint(WsdlImporter, WsdlEndpointConversionContext)

在匯入端點時呼叫。Called when importing an endpoint.

適用於