CustomChannelsTester是一種工具,可用來針對一組預先定義的服務合約測試自定義通道實作。 您可以選取一組服務合約,並使用 XML 檔案將其傳遞至工具。 接著,此工具會產生服務與用戶端,以在訊息交換期間執行自定義通道實作。
開始建置工具
若要建置解決方案,請遵循 建置 Windows Communication Foundation 範例中的指示。
建置解決方案會產生三個檔案:CustomChannelsTester.exe、TestSpec.xml 和 SampleRun.cmd。 檔案SampleRun.cmd有範例命令行,示範如何使用此工具來測試 傳輸:UDP 範例。
執行工具
在命令提示字元中,輸入下列命令:
CustomChannelsTester.exe /binding:YourCustomBindingName /dll:TheAssemblyWhereThisTypeIsDefined /testspec:XmlFileNameWhichContainsTestOptions使用
/binding選項是必須的。/dll如果「系結」不是 Windows Communication Foundation (WCF) 所提供的系統提供的系結,則為必要項。/testspec是選擇性的。這會根據測試規格和系結來建立伺服器和用戶端。
執行客戶端和伺服器,並傳回結果。
以下是測試規格描述的範例 XML (testspec.xml):
<TestSpec xmlns="http://WCF/TestSpec" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <ServiceContract> <!-- Test a contract which has oneway / twoway operations. If you set ExpandAll = true, both types of contracts are tested --> <IsOneWay ExpandAll="true">true</IsOneWay> <!-- Test a contract with Asynchronous / Synchronous Operations--> <IsAsync>false</IsAsync> <!-- Test a sessionful / sessionless contract--> <IsSession ExpandAll="true">true</IsSession> <!-- If the Service Contract includes a CallBack Contract--> <IsCallBack ExpandAll="true">true</IsCallBack> </ServiceContract> <TestDetails> <!-- Name of the machine that runs the server - required if you want to run the test crossmachine--> <ServerName>ReplaceThisWithTheServerMachineName</ServerName> <!-- Port Number - Optional--> <Port>8000</Port> <!--URI for the callBack address for the client. The client will receive the messages from the server on this address in case of a CallBack Contract--> <ClientCallBackAddress/> <!-- Duration (in sec) after the server has started, it times out - optional(default = 300sec) --> <ServerTimeout>300</ServerTimeout> <!-- Duration (in sec) before the Client initializes -optional(default = 60sec) --> <ClientTimeout>60</ClientTimeout> <!-- Number of clients for each service - optional(default = 1) --> <NumberOfClients>1</NumberOfClients> <!-- Number of messages each client sends to the service - optional(default = 1) --> <MessagesPerClient>1</MessagesPerClient> </TestDetails> </TestSpec>