您的位置:首页 > 编程语言

WCF应用:宿主与调用纯代码示例(Host &Client code only sample)

2012-11-27 14:13 435 查看
There are different ways to host a WCF appliaction. You can host it in:

IIS

WAS

Windows service

console application

The last one is very simple to do and I’ll will showYou how to do it.

First, create a new WCF Service Appliaction project. Then open the IService1.cs interface and add a custom method:

After that, implement this method in the Service1.svc.cs file. I did it like this:

Next create a new Console Application project and fill the Main function with this content:

That’s it. Now You have a fully functional WCF Service. TO test it You can create second console project and fill it like this:

ServiceReference1 is a reference You have to add to Your project. Simply do it by clicking RMB on the “Service Reference” node and the “Add Service Reference…”. Next step is to click “Discover” and when Your svc file is found click OK.





OK, now You can run first the service console app and then the test console app and You should see the results like this:





No tags
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐