tailieunhanh - Lập trình .net 4.0 và visual studio 2010 part 23

Windows Communication Foundation (WCF) phát triển sẽ được vui để biết rằng lần này của WCF không nên phá vỡ các ứng dụng hiện có. Trọng tâm trong WCF 4 đã được để làm cho nó dễ dàng hơn để sử dụng trong khi cũng mang lại trong một số tính năng mới, chẳng hạn như định tuyến, hỗ trợ giao thức WS-Khám phá (một phương pháp để phát hiện dịch vụ), và một số cải tiến từ REST WCF starter kit | CHAPTER 7 Windows Communication Foundation Availability Framework 4 Windows Communication Foundation WCF developers will be glad to know that this release of WCF shouldn t break any existing applications. The focus in WCF 4 has been to make it easier to use while also bringing in some new features such as routing support for WS-Discover protocol a method for discovering services and some enhancements from the WCF REST starter kit. WCF and Workflow Foundation WF are more closely integrated than ever in .NET so please refer to Chapter 6 for details of the new WF changes in particular WF services . You should also be aware that there are some changes at the CLR level that may affect your WCF applications that were covered in Chapter 4. NOTE You can download many samples for WCF from http en-us netframework . I ll refer to a few in this chapter. Configless WCF One of the most frustrating aspects of WCF for me was the massive amount of configuration needed it always seemed to be much harder to configure than it should be especially when compared with the simplicity of creating an asmx services. With great flexibility and power comes great big XML configuration file. WCF4 allows you to create a service with no configuration file at all in just a few lines of code. Let s do this now. 1. Create a new WCF Service Library project called . 2. Add a console application to the solution called . 3. In add a reference to and the assembly. 159 CHAPTER 7 WINDOWS COMMUNICATION FOUNDATION 4. In the add the following using directive using 5. Enter the following code in s Main method to instantiate our service ServiceHost MyServiceHost new ServiceHost typeof new Uri http localhost 8888 Chapter7 .