954,577 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Unable to access asp.net web service from javascript

Hi All,
I am having issue in calling asp.net web service from javascript. The web service resides in one of our development machine and i am trying to call the web service from my local machine. (The application works fine if the webservice resides in my local machine) The reference for webservice is added to Scriptmanager.
ScriptManager1.Services.Add(new ServiceReference("http://xxx.xxx.xx.xx/MyService/Service.asmx");

I debugged the code.. The scriptmanager takes the correct webservice reference. The client proxy files (jsdebug) are also generating correctly. But when i call the webservice it seems to take localhost as the root instead of the development machine ip (noticed using firebug). Please help me to solve this issue

Thanks

anish.anick
Light Poster
47 posts since Jan 2008
Reputation Points: 10
Solved Threads: 3
 

What if:
1. you first create the follwing in the web.config file

<appSettings>
    <add key="servicePath" value="http://yourmachin/MyService/Service.asmx"/>
  </appSettings>

2. Then you add using System.Configuration; in the source file
3. in the page load method:

protected void Page_Load(object sender, EventArgs e)
        {
            ScriptManager1.Services.Add(new ServiceReference(ConfigurationManager.AppSettings["servicePath"].ToString()));
        }


Will this help?

/Frank

frank@furnes.nu
Newbie Poster
12 posts since Feb 2009
Reputation Points: 10
Solved Threads: 1
 

Hi Frank,
I am also doing the same procedure. While debugging i can see that the ScriptManager takes the correct webservice path as in the webconfig file. The scriptmanager also creates the client proxy files correctly. But once the page gets loaded in the browser the web service URL is changed back to localhost instead of the development machine URL ("http://xxx.xxx.xx.xx/.....") . I can also see that the URL is correctly redendered in the source file.

Thanks

anish.anick
Light Poster
47 posts since Jan 2008
Reputation Points: 10
Solved Threads: 3
 

Hi Again
It seems like you have to create a webservice wrapper, when calling "external" webservices with ajax

I found some info on these sites:
http://msdn.microsoft.com/en-us/magazine/cc163499.aspx
http://www.developer.com/net/asp/article.php/10917_3657826_4
http://forums.asp.net/t/1111617.aspx

Hope this helps

frank@furnes.nu
Newbie Poster
12 posts since Feb 2009
Reputation Points: 10
Solved Threads: 1
 

Hi,
I was already setting the ScriptService enabled webservice path in web.config and adding a new scriptreference to the ScriptManager, just like Frank mentions.. When I build my website and then run I am able to get results. But my issue is I want to be able to debug as well at least in my development environment on my machine through ASP.Net solution. Hence when I try to debug I see in the AJAX generated code, when it is trying to invoke the result of this._get_path() has only virtual directory onwards (not the localhost/... ) and when I in the QuickWatch window try to reset it to be with the whole http://localhost/myvirtualdir ... it gives me access denied when I try to execute right after resetting the path. It is a pain not to be able to debug from the client side. I have to have a test button to call the webservice on the server side to make sure I get the results and then put the call on the client side and build the website to see the results, that is what it is amounting to right now. Totally frustrating. Any help is appreciated.

... LotusShiv

LotusShiv
Newbie Poster
4 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You