Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Working with JsonHTTPHandler

, 13 Nov 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Introduction...

Introduction

This little code just gives you hands on trick to access Webservice using JavaScript.

Background

I knew that webservice can be accessed by JavaScript, but haven't thought that there was such an easy way. Have a look at it.

Using the Code

Let's start step by step.

Step 1

Add Script Manager Instance to your ASPX Page. Here I have specified path of my webservice (QuoteService.asmx).

 
<asp:ScriptManager ID="_ScriptManager" runat="server">
            <Services>
                <asp:ServiceReference Path="~/QuoteService.asmx" />
            </Services>
        </asp:ScriptManager>
 

Step 2

Add the below mentioned attribute to your code behind of Webservice (in my case QuoteService.cs)

 
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
 

And write some method to your Webservice Code Behind Class. (In my case QuoteService.cs)

 
[WebMethod]
public string GetQuote(int intVar)
{
return (intVar + 6).ToString();
}
 

Step 3


Call a Function from JavaScript and define the Return value handler of function.

 
function LookUp() {
            QuoteService.GetQuote(2, OnLookupComplete)
        }
 

Define result Handler Function as depicted in the above code.

 
function OnLookupComplete(result) {
            alert(result);
        }
 

So guys, we are done with our tricks.

 

Points of Interest

I just was thinking it will be a very time consuming concept to calling webservice from JavaScript, but as I searched through net, I found a very simple solution, so I thought it may be useful to you also in some part of code.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Hiren solanki
Software Developer
India India
He is a Smart IT devloper with Few years of Expeariance But having Great command on ASP.net,C#,SQL Query,SSRS,Crystal Reports
 
Apart from that He Loves multimedia work too, Master of Adobe photoshop, Illustrator, CSS , HTML and all things.
 
He is Currently working in Microsoft Dynamics CRM and Having Nice Expearince with CRM. CRM Rocks!!!

Comments and Discussions

 
GeneralGreat tip! Thanx..... PinmemberJeroenVonk11-Nov-10 4:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 13 Nov 2010
Article Copyright 2010 by Hiren solanki
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid