calling WebService from javascript client

F

Frank

Hi,

Newbie wondering if it is possible to call an ASP.NET 2.0 WebService from
javascript that isn't served up on the same server?

For example, I would like to call the WebService using an XmlHttpRequest
object, but it appears that I can't just run the webservice using because
the calling javascript doesn't know about the client proxy js right?

So how do you do this if you want to call the webservice from a javascript
client?

In my webservice, I have used:
At the top of the file:
[System.Web.Script.Services.ScriptService]

And then right where I define my method:

[WebMethod]
[System.Web.Script.Services.ScriptMethod]

public string MyWebMethod() {

return "hello world";

}



Or should I be using IHttpRequest Module to handle this situation?

Thanks for any tips,
Frank
 
F

Frank

er, yea, HTTP GET and HTTP POST ...
I've got my head stuck in proxy client consumption and totally forgot these
services can be called via get and post
 
L

Laurent Bugnion [MVP]

Hi,
er, yea, HTTP GET and HTTP POST ...
I've got my head stuck in proxy client consumption and totally forgot these
services can be called via get and post

However, XmlHttpRequest doesn't allow cross-domain service calls. You
may only call the site of origin. This is an annoying limitation, which
may be lifted in the future (maybe using JSONRequest or something
similar), but one you have to live with when you use a
webbrowser-to-webserver webservice call.

The alternative is to use a server as proxy ("forwarding" the calls), or
to use other techniques, for example including script files from the
third party server (if they're available). This is the technique Google
uses for the maps and other services.

HTH,
Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top