Archive for July, 2008

Accessing ASP.NET Web Services with Dojo

Tuesday, July 29th, 2008

A while back, Dave wrote a post on this subject. Last week, I decided to pick up where he left off.

I’ve got some web services that take parameters so I decided to try to figure out how to pass the parameters up using dojo.xhrGet. You’ll have to check out Dave’s post for the fundamentals but here’s what I did. I created a criteria object with the parameters that I needed to pass to the webservice (the vals object was returned by a call to my dojo dialog’s getValues method):

var criteria = { “projectName”:’”‘ + vals.projectName + ‘”‘, “bufferDistance”:vals.bufferDistance };

then I added the criteria to my dojo.xhrGet (note the ‘content: criteria’ part):

dojo.xhrGet({
    url: 'Services/FuelsSearchService.asmx/GetByProject',
    handleAs: 'json',
    contentType: "application/json; charset=utf-8",
    content: criteria,
    load: handleFuelsResults,
    error: callbackError,
    timeout: 10000
});

And it works!

Well, not right away. See those funky extra quotes around the projectName value? Well it wouldn’t work until I added those. Even though you and I know that vals.projectName is a string, dojo knows it’s a string, and javascript knows it’s a string, Microsoft’s javascript deserialization stuff apparently doesn’t know that. I kept getting “Error: bad http response code:500″. But when I actually looked at the response in Firebug, it said, “Invalid JSON primitive: Cities.” Cities is the value of vals.projectName. So I added the extra quotes and voila, it works. But it’s ugly. Anybody know another way?

Hello world!

Thursday, July 3rd, 2008

So, this is my blog. I’ll probably mostly write about GIS software development here. If you want pictures of my kids and such, check out my other blog.