共用方式為


IWsdlImportExtension.ImportContract 方法

定義

在匯入合約時呼叫。

public:
 void ImportContract(System::ServiceModel::Description::WsdlImporter ^ importer, System::ServiceModel::Description::WsdlContractConversionContext ^ context);
public void ImportContract (System.ServiceModel.Description.WsdlImporter importer, System.ServiceModel.Description.WsdlContractConversionContext context);
abstract member ImportContract : System.ServiceModel.Description.WsdlImporter * System.ServiceModel.Description.WsdlContractConversionContext -> unit
Public Sub ImportContract (importer As WsdlImporter, context As WsdlContractConversionContext)

參數

importer
WsdlImporter

匯入工具。

context
WsdlContractConversionContext

要修改的匯入內容。

範例

下列程式碼範例示範 如何使用 IWsdlImportExtension 來新增 System.ServiceModel.Description.IServiceContractGenerationExtensionSystem.ServiceModel.Description.IOperationContractGenerationExtension (WsdlDocumentationImporter ,在此案例中) 修改介面和作業層級產生的 WCF 用戶端程式代碼。

  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));
              }
          }
      }
  }

下列程式碼範例會示範如何設定用戶端中繼資料系統,以便從應用程式組態檔使用自訂 IWsdlImportExtension

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

備註

當合約正在匯入時,會呼叫 ImportContract 方法。 您可以修改合約或插入其他的匯出行為,例如 System.ServiceModel.Description.IServiceContractGenerationExtensionSystem.ServiceModel.Description.IOperationContractGenerationExtension 物件,以修改針對合約所產生的程式碼。

適用於