共用方式為


如何建立 .NET 應用程式以測試使用 BizTalk WCF 服務發佈精靈發佈的 WCF 服務

若要測試已發佈的 WCF 服務,您可以建立 .NET 應用程式,讓它使用您已發佈的 WCF 服務的。 本主題說明如何建立 .NET 應用程式來測試已發佈的 WCF 服務。

注意

Visual Studio 說明集合中包含實用的逐步解說,說明如何建立使用 WCF 服務的 .NET 應用程式。 您可以使用這個逐步解說來測試您已發佈的 WCF 服務。 For information and procedures about creating a WCF client project, see "Walkthrough: Accessing an XML Web Service Using Visual Basic or Visual C#" in the Visual Studio Help Collection at https://go.microsoft.com/fwlink/?LinkId=62263.

注意

本主題使用 Service Model Metadata Utility 工具 (SvcUtil.exe) 建立 WCF Proxy 類別和應用程式組態檔。 SvcUtil.exe 包含在 Windows Vista 和 .NET Framework 執行階段元件的 Microsoft Windows 軟體開發套件 (SDK) 中。

若要建立簡單的 WCF Proxy 類別和應用程式組態檔

  1. 開啟 CMD 殼層,如下所示:按一下[開始]、指向[所有程式]、指向[Microsoft Windows SDK],然後按一下[CMD 殼層]。

  2. 在 [CMD Shell] 中,移到您要放置 Proxy 類別和應用程式組態檔的目錄。

  3. 在 [CMD Shell] 中,執行 ServiceModel 中繼資料公用程式工具 (SvcUtil.exe),使用下列程式碼為已發佈的 WCF 服務建立 Proxy 類別和應用程式組態檔:

    svcutil <http://servername/apppath/wcfservicename.svc> /config:App.config
    

    注意

    這個命令列會產生 BizTalkServiceInstance.cs 和 App.config,前者為 Proxy 類別,後者則為應用程式組態。 For more information about Svcutil.exe, see "Service Model Metadata Utility Tool (Svcutil.exe)" at https://go.microsoft.com/fwlink/?LinkId=74696.

若要編譯使用已發佈之 WCF 服務的 .NET 應用程式

  1. 在 Visual Studio 的 [方案總管] 中,將 SvcUtil.exe 建立的檔案、BizTalkServiceInstance 和 App.config, 加入專案中。

  2. 在 Visual Studio 的 [方案總管] 中,確定加入 System.ServiceModel.dll 的參考,以編譯 Proxy 程式碼。

  3. 建立程式碼,以使用產生的 Proxy 程式碼。 下列程式碼顯示如何使用產生的 Proxy:

    DeliveryNotification deliveryNotification= new DeliveryNotification();
    deliveryNotification.TrackingNumber = "001";
                Microsoft_Samples_BizTalk_WCFBasicHttp_BizTalkApp_DeliveryRequestProcess_DeliveryNotificationReceivePortClient service = new Microsoft_Samples_BizTalk_WCFBasicHttp_BizTalkApp_DeliveryRequestProcess_DeliveryNotificationReceivePortClient("BasicHttpBinding_ITwoWayAsyncVoid");
    service.Submit(deliveryNotification);
    
  4. 執行 .NET 應用程式,將訊息傳送到已發佈的 WCF 服務。

另請參閱

利用 WCF 接收配接器發佈 WCF 服務時的考量