AJAX + Webserivces = error 12030

K

kpg

I have an AJAX enabled web service consumed by an AJAX
enabled web app, given a zip code it returns the city
and state.

Tested the web service, it works fine.

I created a services collection in the script manager
and pointed to my web service.

I call the web service from an html input button click,
per MS examples.

I get a 12030 error.

Now it seems the web service must be in the same domain
as the web app, while this is a severe limitation I
figured this was the problem.

So I created the web service on my localhost, I get
the same error.

I played around with page methods but kept getting object
not defined errors so I gave up on that. (It seems the
web method must be declared in the aspx file, but I still
get this error.)

Considering that the same domain limitation was enough to
make the whole effort pointless (the web service will NOT
be in the same domain as the web app) I thought I would go
the traditional route and use xmlhttprequest. I've used
It before in asp.net 1.1 and it worked well.

So I copy my working code from a 1.1 app, change the url to
point to my Web service, invoke it and get access denied.

Why access denied? No doubt it's MS protecting me from
myself again.

Here's the code:

I'm using ?wsdl just to get some xml back for testing.

function Button1_onclick() {
debugger;
var url = 'http://localhost/webServices/ZipCode/ZipCodeService.asmx?
wsdl';
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = onComplete;
req.open("POST", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = onComplete;
req.open("POST", url, true);
req.send();
}
}
}

function onComplete(arg,usercontent) {
debugger;
if (req.readyState == 4) {
if (req.status == 200) {
// ...processing statements go here...
} else {
window.status="There was a problem retrieving the XML
data:" + req.statusText;
}
}
}

Alternately I would love to use ASP.AJAX features to do this the
'right' way, but that 12030 error occurs no matter what I try.

I'm sure I could get an update panel to work, but that requires a
postback and processing of the page, even though the user's page is
not refreshed- that seems to defeat the purpose of doing AJAX in the
first place.

kpg
 
G

George Ter-Saakov

It's a security feature.
IE and Firefox will not let you connect to other server than the one page
was served from.

George.
 
K

kpg

George Ter-Saakov said:
It's a security feature.
IE and Firefox will not let you connect to other server than the one page
was served from.

George.

OK. I called it from localhost. I'm thinking this worked in asp.net 1.1
because my
1.1 app ran on the local IIS, whereas my asp.net 2.0 app is file based and
does
not run on my local IIS, but in an asp.net 2.0 process. Does that should
correct?

That would explain it.

So how would I test this from a file based project? Do I have to have the
web service included in the solution? Or perhaps add the web project
to my local IIS?

I think I'll just use an update panel. Is there a way in page_load or
better
still page_init to determine if a postback is the result of an update panel
post? That way I could circumvent any unnecessary processing.

Also, using an update panel, I could reference my external web service
and call it server side - rather like using my server as a proxy for the web
service.

TIA
kpg
 
K

kpg

Finally got it to work.

Problem was mostly me. I (for some reason) could not let go
of the idea that a web service was a standalone service on a
server, independent of the web application. The concept of
having an asmx file as part of a project mixed in with the
standard aspx files escaped me. Sure, that's exactly what the
video tutorial showed, but I was thinking this was not how
such a project would be deployed. Silly me.

The solution is really quite simple.

1. Add an web service page to the web app.

2. Reference it in the script manager. In my
case this resides in a master page.

3. In javascript call the web service:

var ret = myclass.mywebservice(myargs, onComplete, OnFailure, usercontent);

Provide the callback functions onComplete and onFailure .

4. If the web service is external, create a web reference in the
project, then in the local asmx page call the referenced web
service, otherwise just perform the logic there.


In reviewing my asp 1.1 httprequest code (that works) I actually
post to an aspx page in the same project and the page returns an
xml response (a cool trick I can show if anyone's interested).
This technique is really quite similar to that described above,
except in the above the ASP.AJAX code handles most of the
troublesome details.

kpg
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top