</configuration>
In the Service.cs
file located in the App_Code folder, give the service a namespace of 'WCFService
', and code the following GetServerTime()
method:
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
public class Service {
// Add [WebGet] attribute to use HTTP GET
[OperationContract]
public void DoWork() {
// Add your operation implementation here return;
}
}
In the Source view of Default.aspx
, add the following highlighted code:
<form id='form1' runat='server'>
<div>
</div>
</form>
This adds an instance of the <ScriptManager>
control to the page and references the WCF service (Service.svc
). It also adds a Button control to the page.
Insert the following JavaScript code into Default.aspx
:
<body>
<form id='form1' runat='server'>
The Button1_onclick()
JavaScript function is invoked when the button on the page is clicked. It calls the WCF service and the returning result is retrieved via the CallBackFunction()
function.
Press F5 to debug the application. You can now click the Get Server Time button to obtain the server time without causing a refresh on the web page (see Figure 20-47).

Figure 20-47
Summary
This chapter provided an overview of WCF and explained how it differs from traditional ASMX Web Services. It explored the limitations of Web Services today and examined how WCF aims to provide a better way of writing and hosting your services. The various examples shown throughout this chapter afford concrete illustrations of what WCF offers and hopefully provide enough motivations for you to explore this important technology further.
Part III
Appendixes
Appendix A
C# Keywords