Zaiyue Xue, Microsoft STB China
WCF Test Client is a debugging tool to test WCF service. It is very useful to help developing WCF service. In this blog, I will share some tips on how to launch WCF Test Client in Visual Studio.
There are 2 ways to start WCF Test Client out of Visual Studio. The first way is double click WcfTestClient.exe in the folder “Visual Studio installation path\Common7\IDE”. The other way is type the “WcfTestClient” command in “Visual Studio Command Prompt” as shown in Diagram 1:
Diagram 1
In Visual Studio, different project templates provide different ways to launch WCF Test Client. The following form is all the WCF related project templates in Visual Studio 2010 Beta2:
Template Name
Template Path
.NET Framework Version
WCF Service Library
New Project -> WCF Node
3.0/3.5/4.0
WCF Service Application
New Project -> Web Node
WCF Workflow Service Application
4.0
Sequential Workflow Service Library
3.5
State Machine Workflow Service Library
Syndication Service Library
3.5/4.0
WCF Service
New Web Site
Form 1
WCF Service Library, Sequential Workflow Service Library and State Machine Workflow Service Library:
When starting debugging (F5), it will host the service in the WCF Service Host by default. And the WCF Test Client will automatically start for you to test the service. Please see the Diagram 2:
Diagram 2
If you don’t want to start WCF Test Client when pressing F5, you can edit “Project Properties -> Debug -> Command line arguments” as shown in Diagram 3:
Diagram 3
WCF Service Application and WCF Workflow Service Application:
If you set the focus on the .svc or .xamlx file in Solution Explorer, WCF Test Client will start when pressing F5. Please see the diagram 4:
Diagram 4
If you don’t want to use WCF Test Client when pressing F5, you can add the setting of EnableWcfTestClientForSVC property in .csproj.user file to disable WCF Test Client:
<Project> <ProjectExtensions> <VisualStudio> <FlavorProperties> <WebProjectProperties> <EnableWcfTestClientForSVC>False</EnableWcfTestClientForSVC> </WebProjectProperties> </FlavorProperties> </VisualStudio> </ProjectExtensions> </Project>
<Project>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties>
<WebProjectProperties>
<EnableWcfTestClientForSVC>False</EnableWcfTestClientForSVC>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
By the way, .csproj file has the default value setting for EnableWcfTestClientForSVC property. If .csproj.user doesn’t set the EnableWcfTestClientForSVC property, it will use the default value in .csproj file:
<Project> <ProjectExtensions> <VisualStudio> <FlavorProperties> <WebProjectProperties> <EnableWcfTestClientForSVCDefaultValue>False</EnableWcfTestClientForSVCDefaultValue> </WebProjectProperties> </FlavorProperties> </VisualStudio> </ProjectExtensions> </Project>
<EnableWcfTestClientForSVCDefaultValue>False</EnableWcfTestClientForSVCDefaultValue>
The following form shows the detail logic for which client is launching by setting the specific property of .csproj.user and .csproj files:
.csproj.user file setting
True
False
Not Set
.csproj file setting
True/False/Not Set
client launching
WCF Test Client
IE
Form 2
For example, in a project group who are using the source control, the .csproj.user file won’t be checked in, while the .csproj file will be checked in. If you only want to change the launching behavior for yourself, you should change the .csproj.user file. If you want to change the launching behavior for the whole group, you should change the .csproj file.
Syndication Service Library:
WCF Test client doesn’t support to test the kind of service, so the WCF Test client won’t start in this project.
WCF Service (Web Site):
WCF Test Client won’t be launched automatically when pressing F5. If you want to get the same launching behavior as WCF Service Application, you can change the websites.xml file as following (at “C:\Users\<username>\AppData\Local\Microsoft\WebsiteCache” folder. XP/2003 is in a similar location):
<DesignTimeData> <Website RootUrl="C:\" CacheFolder="WCFService1" EnableWcfTestClientForSVC="true"/> </DesignTimeData>
<DesignTimeData>
<Website RootUrl="C:\" CacheFolder="WCFService1" EnableWcfTestClientForSVC="true"/>
</DesignTimeData>
You need to close your solution, and then make the above change. It only loads the property up when project load time and will overwrite when the project closed.