WCF Service 的创建,测试,发布与使用示例
一, WCF Service 的创建: WCF Service Application
注:
- 为了在 IIS 或 WAS 中托管,则必须使用 WCF Service Application 类型,参看右侧的说明。
- 如准备使用 Windows Service 托管,则可使用 WCF Service Library 类型
1,创建 WCF Service Application
2,对应准备相关代码
F2 to Rename
3,开发时可能的出错及解决
- 基于 Markup , 可查看相应的代码,以确认相应的 Service & Codebehind 中的值是否正确
4,测试确认OK
F5 执行, WCF Test Client
二,WCF Service 的发布,至 IIS
1,将创建好的 WCF Application 文件 Copy 至 IIS 对应目录下
2,在 IIS 中创建 Application
- 非直接创建 Web site ,而是使用 Default Web Site 下的 Add Application…
3,在 IIS 中确认发布成功
4,在 PC 中测试确认
使用 svcTestClient.exe 进行测试
三,WCF Service 的调用示例
1, 创建一个 Console Application 用以测试 :Wcf_Client
2, 添加 Service Reference
3, 添加调用代码
代码
static void Main(string[] args)
{
wcfCalculator.CalculatorClient client = new wcfCalculator.CalculatorClient("BasicHttpBinding_ICalculator");
double _result = client.Add(3, 5);
Console.WriteLine(" 3 + 5 = {0}", _result);
_result = client.Multiply(3, 5);
Console.WriteLine(" 3 * 5 = {0}", _result);
Console.WriteLine("Press Entry key to end ...");
string readkey = Console.ReadLine();
}
4,可能的错误与解决
- Pass a valid endpoint name to service client constructor
注:如仅有一个 Endpoint ,可留空,否则必须指定对应的 Endpoint Name
Endpint Name 即 Port Name , 如下
5, 测试及结果
四, svcTestClient.exe WCF 测试工具的使用
整合使用
为何在运行 WCF Service 时,有时 svcutil.exe 会出现,有时不出现?什么条件影响?
- 如果打开并焦点放在非 .svc.cs 文件后, F5 运行,则打开 Browser
- 如果打开并焦点放在 .svc.cs 文件后,F5 运行,则可打开 svcutil.exe
独立测试 SVC 使用
文件位置:“C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDE”
可打开在 Command Prompt 中运行,然后添加相关的 Service URL 进行测试
参考文档及说明
如何使用WCF调试器WcfTestClient.exe
From <如何使用WCF调试器WcfTestClient.exe - dapeng888 - 博客园>
WCF 测试客户端 (WcfTestClient.exe)
WindowsCommunication Foundation (WCF) 测试客户端 (WcfTestClient.exe) 是一种 GUI 工具,使用户能够输入测试参数、将输入提交到服务以及查看服务发送回的响应。 与 WCF 服务主机结合使用时,它可提供无缝服务测试体验。
通常可以在以下位置找到 WCF 测试客户端 (WcfTestClient.exe) :- Community 可以是 C:Program Files (x86)Microsoft Visual Studio2017CommunityCommon7IDE "Enterprise"、"Professional"或"Community"之一,具体取决于安装的 Visual Studio 级别。
From



