Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
 How to call webservices from remote server with java script
Posted by Ajay Bhushan on  3/28/2009 6:49:17 AM Category: ADO.NET
Add to my favorites
Email to friend

I’m mailing script for Adserver using DotNet 2.0. Facing the problem as given below:

Created a webservice named 'WebService.cs' in my project in app_code folder, its respective .asmx file is in my main project folder(outside app_code).

Now this project is published and uploaded.

When someone logins on my website as a publisher, he gets the following script to paste

<body onLoad="return TaggedData('ws','1','PUBID01','adht','adwidth','categorycode','#f5f5dc','#ffffff','#a9a9a9','#ffffff','#006400');" >

<script src="" type="text/javascript"></script>

<div ID="ws" title="hello" style="BEHAVIOR:url(" onresult="GetResult('Div1Resul');"></div>

<div ID="Div1Resul"></div>

Above script calls the javascript named 'Javascript.js' in my online project, this javascript in return calls my webservice named ‘WebService.cs' through the code :-


which ultimately displays the desired records from the database. Now,

1. It does not work when the above mentioned script is called in a html/dotnet file within the same domain or any other domain. It reaches the online javascript file but then stops without displaying the record. file is placed within the same folder.

It gives the error:

Object doesn’t support this property or method.

Even when is placed along with the script file or removed from there.

2. In the localhost path above mentioned script is placed in an aspx page. Along with this, a file is also placed in the same folder as the aspx page. It reaches the local javascript file, then calls the local webservice.asmx and displays the desired record.

3. It also works fine when the above mentioned script is in html format along with on desktop with internet connectivity.

It reaches the online javascript file, then calls the webservice.asmx file and displays the desired record.

Post Your Reply Post New Question

 Viewer's Reply
Solution: How to call webservices from remote server with java script
Answered By Moderator1 on 4/1/2009 8:01:10 PM
Check the article in the below url,

It shows an easy way to access web service from the JavaScript. You have make use of AJAX ScriptManager as the code below,

<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:ServiceReference Path="WebService.asmx" />

Then in JavaScript, create a function to call the web method, and another javascript function to display the result from the WebService.

function fnCallMyWebMethod()

function fnDisplayResult(result)
Add Script Services Reference in your Web Service
Answered By Moderator1 on 4/1/2009 8:23:02 PM

In order to call the WebService, in JavaScript through ScriptManager, you have to add the below code reference in your webservice at the declaration part.


That's it hope this will help you.
Post Your Reply If you still have problem, post it again under this reply for better response.

Sponsored by
When Good HTML Goes Bad: How You Can Protect Your Web Applications
Introduction to Software Development
Many .NET teams are underperforming, is yours?