Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 4453 |  Welcome, Guest!   Register  Login
Home > Articles > WCF > Ajax Enabled WCF Service

Ajax Enabled WCF Service

Article posted by Anup1252000 on 2/15/2010 | Views: 8044 | Category: WCF | Level: Beginner red flag


In this article, we are going to see how to use Ajax Enabled WCF Service in a website.

Introduction

        In this article, we are going to see how to use Ajax Enabled WCF Service in a website. Let us go through this application Step by Step.

Step 1:

       Open VS2008->create new website->name it->Right click on the website->Add new item ->Select Ajax Enabled WCF Service->name it as Service.svc which is by default at the first instance.

 

Step 2:

     Now lets write simple lines of code in service.cs class which is located in App_code folder.

using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service
{
// Add [WebGet] attribute to use HTTP GET
[OperationContract]
public string HelloWorld()
{
// Add your operation implementation here
return "Hello World";
}
// Add more operations here and mark them with [OperationContract]
}

This HelloWorld method just returns simple string value as HelloWorld.

Step 3:

       Now lets go to Default.aspx->Add new ScriptManger->give service reference to Service.svc

      

Here we added html button and a span. Click on the html button automatically it will script tag.

<script language="javascript" type="text/javascript">
function Button1_onclick() {
}
</script>
Within the Button1_onclick function writes these lines
<script language="javascript" type="text/javascript">
// <!CDATA[
function Button1_onclick() {
Service.HelloWorld(onsuccess,onfailed,"Hello world example");
}
function onsuccess(results)
{
message.innerHTML=results;
}
function onfailed(results)
{
message.innerHTML=results;
}
// ]]>
</script>

 

Step 4:

       Now lets go to the Web.config file. By default only WebHttpBinding has been created.so We are suppose to add metadata, in this case it is mexHttpBinding.

  

 

I hope you people like this article.


If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

About anup hosur

Experience:2 year(s)
Home page:
Member since:Saturday, August 01, 2009
Level:Starter
Status: [Member]
Biography:
>> Write Response - Respond to this post and get points
Related Posts

The aim of this article is to explain the basics of WCF in a manner as simple as possible. It is assumed that the reader doesn’t know anything about WCF or .NET 3.0, however he/she is expected to know .NET 2.0 and/or simple facts like what is a web service. While writing this article (or any other) I always try to avoid difficult technical words, which may confuse the reader. I have tried to put it in as simple words as possible. At the end of this article, I would hope you understand at least some of the key WCF areas and possibly be inspired enough to try out a project on your own.

In this article we will revisit the ABCs of WCF and see some practical scenario.

In this article we will start with transport and message security understanding. We will then see simple code samples of how to implement transport and message security using WsHTTP bindings. We will also see what is the difference between ‘BasicHttpBinding’ and ‘WsHttpBinding’ with the help of a simple source code. WCF security is a huge topic by itself, but we are sure with this article you will get a quick start of how to go about WCF security.

In this article we demonstrate the 4 important steps to enable your WCF service as a REST service.

This is my 5th WCF FAQ article. This article is completely dedicated to WCF transactions. In this article we will understand the WCF transaction protocol, two phases in WCF transaction, transaction options and finally end up with simple sample for WCF transaction.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2012 7:46:48 AM