首页 技术 正文
技术 2022年11月21日
0 收藏 966 点赞 4,228 浏览 2037 个字

You know as a beginner to learn WCF, the first thing is to make a simplest WCF service work like a classic “Hello World” console application. Now I will introduce the steps by following:

1.Create a “WCF Application Service” like this:
How to make a simplest WCF service work on Win7 with VS2010

2. Rename the “IService1” to “ICalculatorService” and “Service1” to “CalculatorService” for both project file name and interface/class name in source code, and then update the generated code by default to following:
How to make a simplest WCF service work on Win7 with VS2010

How to make a simplest WCF service work on Win7 with VS2010

3. Set as start page for “CalculatorService.svc” and then hit F5 to lauch the WCFServiceTestClient

How to make a simplest WCF service work on Win7 with VS2010

4. Open IIS and “Sites->Add Website…”, click OK button as below:

How to make a simplest WCF service work on Win7 with VS2010

5. Right click the new added site and select “Add Virtual Directory…”, after that, switch to “Content View” you can see below:
How to make a simplest WCF service work on Win7 with VS2010

How to make a simplest WCF service work on Win7 with VS2010

6. Right click the new added virtual directory “Calculator” and then select “Convert to Application”, click OK button

7. Right click the converted “Calculator” and then “Manage Applicataion->Browse”

8. If happen below error, need to change the Application Pool’s .NET framework version to 4.0 as following:
How to make a simplest WCF service work on Win7 with VS2010

How to make a simplest WCF service work on Win7 with VS2010

9. If happen below error, need to enable the “Directory Browsing” as the guided steps:

How to make a simplest WCF service work on Win7 with VS2010

10. Repeat step7 and then click the link “CalculatorService.svc”, if you can see the second picture, congratulations!

How to make a simplest WCF service work on Win7 with VS2010

How to make a simplest WCF service work on Win7 with VS2010

11. If you are failed to see above picture, probably some ASP.NET components are not installed, so please first check if the 6 items are existing:

How to make a simplest WCF service work on Win7 with VS2010

If not, please make sure below features are installed:
How to make a simplest WCF service work on Win7 with VS2010How to make a simplest WCF service work on Win7 with VS2010How to make a simplest WCF service work on Win7 with VS2010How to make a simplest WCF service work on Win7 with VS2010

12. Below is the optional steps, if above doesn’t work:

Run cmd as administrator and then cd to “C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation”, execute below commandline:

ServiceModelReg.exe -i

If above step generate any bad impact/result, I mean browse the created WCF service will happen some strange errors, we can rollback by executing below commandline:

ServiceModelReg.exe -u

13. Another optional step is(probably it doesn’t need to do):

How to make a simplest WCF service work on Win7 with VS2010

14. I believe the WCF service is published successfully be above several steps given, from then on, I will create a console applicaiton named “CalculatorClient” to consume the published WCF service.

How to make a simplest WCF service work on Win7 with VS2010

14. Right click “References” and then select “Add Service Reference…”,  input the WCF service address and then click “OK” button:

How to make a simplest WCF service work on Win7 with VS2010

15. Add client code to call WCF service, the calling result is showed as below picture, till now our first WCF learning sample is done here. 🙂
How to make a simplest WCF service work on Win7 with VS2010

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,767
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844