4 - Data communication - Windows Communication Foundation (WCF)
WCF "web services" are part of a much broader spectrum of remote communication enabled through WCF. You will get a much higher degree of flexibility doing things in WCF. ASMX is older than WCF, and anything ASMX can do so can WCF (and more).
Please follow these steps to create and use the WCF "web service" (it will be quite similar to the ASMX):
Right click on your web project folder and choose Add New Item
option. Select WCF Service
as type of the new item and name it as CMSService.svc
2) Visual Studio adds the necessary files and also the service configuration to the web.config file.
New section in web.config:
3) Silverlight 2.0 supports only basicHttpBinding thus our WCF service can only use basicHttpBinding. As you can see WCF uses wsHttpBinding by default so you will need to change it from wsHttpBinding to basicHttpBinding:
4) Modify the interface of your service in ICMSService.cs file to offer the same functionality as ASMX does. It means define method which enables you to search for the users according to the specified expression:
5) Now implement the modified interface in your web service to reach the same results as in ASMX:
6) Your service is created and you will need to reference it in order to be able to call it in your code. Right click on the SilverlightDemo project and choose Add Service Reference option:
7) Locate your new CMSService and specify namespace for its proxy class:
8) Now you are ready to use created WCF service in your SilverlightDemo application. To do so, please update your Page.xaml.cs file with the following block of code. Again, Visusal Studio has created proxy class for your web service which make the work much easier:
This article is part of the Data communication in Silverlight 2.0