<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8285155329676564650</id><updated>2011-11-27T16:02:04.920-08:00</updated><title type='text'>P5 Technologies Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://p5tech.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8285155329676564650/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://p5tech.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Greg Pasquariello</name><uri>http://www.blogger.com/profile/10075277809739612563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8285155329676564650.post-4086556112300963015</id><published>2007-06-26T15:08:00.001-07:00</published><updated>2007-06-26T15:14:01.626-07:00</updated><title type='text'>An ASP.NET Ajax UpdateProgress That Works</title><content type='html'>The ASP.NET Ajax UpdateProgress works ok if you're using the UpdatePanel to pass Ajax calls to your back end page code.  But it doesn't work if you're making webservice calls from within javascript on your page.&lt;br /&gt;&lt;br /&gt;It's easy to add this functionality to your web application however.  All you need to do is to add handlers on Sys.Net.WebRequestManager to handle the invokeRequest and completedRequest events, like so:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;        &lt;br /&gt;       Sys.Net.WebRequestManager.add_invokingRequest(onRequestInvoked);&lt;br /&gt;       Sys.Net.WebRequestManager.add_completedRequest(onRequestCompleted);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Make sure you do this after the ScriptManager control is loaded, otherwise you'll get an exception that Sys.Net doesn't exist.  From there, your code can be as simple or as complicated as you like.  Mine generally looks something like:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;        function onRequestInvoked() {&lt;br /&gt;            var stat = $get("status");&lt;br /&gt;            if (stat != null) stat.style.display = "block";&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        function onRequestCompleted() {&lt;br /&gt;            var stat = $get("status");&lt;br /&gt;            if (stat != null) stat.style.display = "none";&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That's all there is to it!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8285155329676564650-4086556112300963015?l=p5tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://p5tech.blogspot.com/feeds/4086556112300963015/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8285155329676564650&amp;postID=4086556112300963015' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8285155329676564650/posts/default/4086556112300963015'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8285155329676564650/posts/default/4086556112300963015'/><link rel='alternate' type='text/html' href='http://p5tech.blogspot.com/2007/06/aspnet-ajax-updateprogress-that-works.html' title='An ASP.NET Ajax UpdateProgress That Works'/><author><name>Greg Pasquariello</name><uri>http://www.blogger.com/profile/10075277809739612563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8285155329676564650.post-17591590922230712</id><published>2007-05-17T20:58:00.000-07:00</published><updated>2007-05-17T21:18:07.650-07:00</updated><title type='text'>Calling ASP.NET WebServices using Plain Ol' Ajax</title><content type='html'>I recently had a situation in which I needed to call an ASP.NET webservice from a straight HTML/javascript file. I could not use an ASPX file for this, and therefore could not use the ASP.NET Ajax ScriptManager. I had to use good ol' XMLHttpRequest.&lt;br /&gt;&lt;br /&gt;Not a problem. Took a while to put the pieces together, but not a problem. There are some tricks to making it work.&lt;br /&gt;&lt;br /&gt;First, you need the know the URL of your webservice. An ASP.NET webservice URL looks like this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://servername/WebService.asmx/MethodName"&gt;http://servername/WebService.asmx/MethodName&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Note that it must look EXACTLY like this. If you include a trailing "/", you will get an error.&lt;br /&gt;&lt;br /&gt;Next, you need to make sure that HttpPost and HttpGet are enabled for your services. By default, in ASP.NET 2.0, they are not. You can fix this by adding the following to the config file of your webservice:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;system.web&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;webservices&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;protocols&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;add name="HttpGet"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;add name="HttpPost"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/protocols&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/webservices&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/system.web&amp;gt;&lt;br /&gt;&lt;br /&gt;Now comes the fun part. I tried for a while to figure out how to get JSON returned from the web service, and not get SOAP back. A lot of stuff on the web tells you that JSON is the default if you are using the web service as a script service. It's not.&lt;br /&gt;&lt;br /&gt;In order to get JSON back, you MUST add the following header to your request, and you MUST do it after the call to open(). In the example, httpObj is an XMLHttpRequest object:&lt;br /&gt;&lt;br /&gt;        httpObj.open("POST", url, true);&lt;br /&gt;        httpObj.setRequestHeader("Content-Type", "application/json; charset=utf-8");&lt;br /&gt;&lt;br /&gt;        httpObj.send(parameters ? parameters : "");&lt;br /&gt;&lt;br /&gt;Finally, in the example above, "parameters" is passed if it exists, otherwise an empty string is passed.  If parameters exists, it must be in the form of a JSON string.  So, for example, if the Web Service method is expecting a string called "s", your parameters would look like:&lt;br /&gt;&lt;br /&gt;        parameters = "{s: 'Hello World'}";&lt;br /&gt;&lt;br /&gt;That's it!  Happy coding!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8285155329676564650-17591590922230712?l=p5tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://p5tech.blogspot.com/feeds/17591590922230712/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8285155329676564650&amp;postID=17591590922230712' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8285155329676564650/posts/default/17591590922230712'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8285155329676564650/posts/default/17591590922230712'/><link rel='alternate' type='text/html' href='http://p5tech.blogspot.com/2007/05/calling-aspnet-webservices-using-plain.html' title='Calling ASP.NET WebServices using Plain Ol&apos; Ajax'/><author><name>Greg Pasquariello</name><uri>http://www.blogger.com/profile/10075277809739612563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8285155329676564650.post-3851984240780031627</id><published>2007-05-04T12:52:00.000-07:00</published><updated>2007-05-04T12:56:25.870-07:00</updated><title type='text'>ColdFusion WebServices for Ajax</title><content type='html'>As a longtime .NET and Ajax developer, I was a little excited to be asked by a client to implement an Ajax-based website using ColdFusion.  Good to get out of the house every now and then.  In building this app, I learned a lot about how ColdFusion  works, and how to best use it to write services that return data for my browser-side javascript (ajax) calls.  I also discovered that, though there is a lot of information about how to write CF webservices for Ajax apps, it was fragmented, difficult to follow, and often wrong.  Hence this blog.&lt;br /&gt;&lt;br /&gt;If you're unfamiliar with an Ajax app, it's basically made up of two parts.  A server component to supply data (or accept data), and a client component that comprises javascript running in a browser and making HTTP calls to the server component.  There can be a lot more to it than that, but that captures the flavor of it.&lt;br /&gt;&lt;br /&gt;Because the server component typically returns data to the javascript, some data format is required that the server can return and that the client can parse and use.  In many Ajax apps, this is done using JSON, a "stringified" version of a javascript object.  It can also be done using raw text, XML, or whatever, but JSON is often preferred because it is compact, rich enough for most uses, and extremely easy to parse on both the server and the client.  In my app, I initially decided to use JSON.&lt;br /&gt;&lt;br /&gt;In ColdFusion, the normal way to code a webservice is to write a CFC file with function definitions that are defined with remote access, and to return your data using &amp;lt;cfreturn&amp;gt;, like so:&lt;br /&gt;&lt;pre&gt;&amp;lt;cffunction name="getFeatures" access="remote"&amp;gt;&lt;br /&gt;   &amp;lt;cfquery name="myQuery" datasource="MyDatasource"&amp;gt;&lt;br /&gt;       select * from MyTable&lt;br /&gt;   &amp;lt;/cfquery&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;cfreturn #myQuery#&amp;gt;&lt;br /&gt;&amp;lt;/cffunction&amp;gt;&lt;/pre&gt;&lt;br /&gt;This will allow you to call the "getFeatures" function from your javascript code.  The returned data can then ostensibly be parsed and used in the javascript on the client.&lt;br /&gt;&lt;br /&gt;However.... when the &amp;lt;cfreturn&amp;gt; tag returns the data, it wraps it in bunch of webservice XML called WDDX (other technologies, like .NET, wrap the returned data in SOAP).  This is problematic for the client, because it's non-trivial to parse the data out of the WDDX wrapper.&lt;br /&gt;&lt;br /&gt;If you recall, I initially wanted to use JSON so that it was easy to use the returned data in my client.  To convert to JSON, I use the CFJASON converter available at &lt;a href="http://www.epiphantastic.com/cfjson/" target="_blank"&gt;http://www.epiphantastic.com/cfjson/&lt;/a&gt;.  Once the conversion is done, it is easy to return the JSON string, but there is a problem, because the JSON is returned to the client still wrapped in WDDX.&lt;br /&gt;&lt;br /&gt;So, there are a couple ways around this.  First, the way CF works, it turns out that it is the &amp;lt;cfreturn&amp;gt; call itself that wraps the return with WDDX.  You can overcome this by outputting the data using &amp;lt;cfoutput&amp;gt; instead:&lt;br /&gt;&lt;pre&gt;&amp;lt;cffunction name="getFeatures" access="remote"&amp;gt;&lt;br /&gt;   &amp;lt;cfquery name="myQuery" datasource="MyDatasource"&amp;gt;&lt;br /&gt;       select * from MyTable&lt;br /&gt;   &amp;lt;/cfquery&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;cfinvoke component="cfcommon.json" method="encode" data="#myQuery#" returnvariable="jsonResult" /&amp;gt;&lt;br /&gt;   &amp;lt;cfoutput&amp;gt;#jsonResult#&amp;lt;/cfoutput&amp;gt;&lt;br /&gt;&amp;lt;/cffunction&amp;gt;&lt;/pre&gt;&lt;br /&gt;As it so happens, this is a pretty good way to write a CF webservice that returns generic JSON and can be consumed by any javascript client.&lt;br /&gt;&lt;br /&gt;There is an additional option, however, that will allow me to return the results using &amp;lt;cfreturn&amp;gt; and still consume the returned values within my javascript.  Check out the  JSMX Engine at &lt;a href="http://www.lalabird.com/" target="_blank"&gt;http://www.lalabird.com/&lt;/a&gt;.  This is a essentially a javascript component that will perform the HTTP call, but then parse the resulting returned data.  If the returned data is raw JSON, it passes back a pre-created javascript object.  If the returned data is WDDX, it also passes back a pre-created javascript object.  Nice!  It will additionally handle a couple of other formats, which makes it a nice tool to have in your utility belt.&lt;br /&gt;&lt;br /&gt;Once I discovered the JSMX at component, I decided to code my webservices without using JSON.  I now can just return the objects from my webservice and let the JSMX engine handle the parsing for me.&lt;br /&gt;&lt;br /&gt;So to summarize, there are two good ways to code a CF webservice that returns data to your javascript clients.  First, you can return a JSON  string (or any other format, for that matter) using &amp;lt;cfoutput&amp;gt; to avoid wrapping the return values in WDDX.  Otherwise, you can use &amp;lt;cfreturn&amp;gt; (and get the returned values wrapped in WDDX), and then use the JSMX engine to deal with the wrapper on the client side.  I chose the latter approach because using the JSMX engine allows me to call both WDDX and JSON webservices without any change to my client code, and without having to modify the "standard" way of doing things on the server.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8285155329676564650-3851984240780031627?l=p5tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://p5tech.blogspot.com/feeds/3851984240780031627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8285155329676564650&amp;postID=3851984240780031627' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8285155329676564650/posts/default/3851984240780031627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8285155329676564650/posts/default/3851984240780031627'/><link rel='alternate' type='text/html' href='http://p5tech.blogspot.com/2007/05/coldfusion-webservices-for-ajax.html' title='ColdFusion WebServices for Ajax'/><author><name>Greg Pasquariello</name><uri>http://www.blogger.com/profile/10075277809739612563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
