Click here to Skip to main content
Click here to Skip to main content

Webservice Using Javascript.

, 27 Aug 2010
Rate this:
Please Sign up or sign in to vote.

Introduction

This Little Code just gives you hands on trick to access Webservice using Javascript.

Background

I had knew that webservice can be accessed by Javascript but haven't thought that much eeasy way. Have a Look at it.

Using the Code

Lets 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 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 above code

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

So Guyz We are done with our Tricks.

Points of Interest

I just was thinking it will be to time taking concept to calling webservice from javascript but as i searched through net . i found very simple solution, so i thought may it will 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

 
Generalif anybody have an alternate then please post it. PinmemberHiren Solanki29-Aug-10 20:03 
GeneralReason for my vote of 5 Thank you for sharing this trick. Pinmemberlinuxjr29-Aug-10 7:27 
Generalthanks @GPU Toaster, Cheers !!! PinmemberHiren Solanki27-Aug-10 2:30 
GeneralNice to know... PinmemberGPUToaster27-Aug-10 1:04 
Generalthanks for your comments. PinmemberHiren Solanki20-Aug-10 16:52 
GeneralThanks for formatting properly. PinmvpKunalChowdhury20-Aug-10 4:25 
GeneralHi Hiren, Can you format it properly? Else, it will not be p... PinmvpKunalChowdhury20-Aug-10 2:05 
Hi Hiren, Can you format it properly? Else, it will not be publish for public view.

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
Web01 | 2.8.140827.1 | Last Updated 27 Aug 2010
Article Copyright 2010 by Hiren solanki
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid