<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ben Dewey - Web, XAML, and Cloud &#187; jQuery</title>
	<atom:link href="http://www.bendewey.com/index.php/tag/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bendewey.com</link>
	<description>Father, Developer, Microsoft MVP, Speaker, and Author</description>
	<lastBuildDate>Sat, 22 Mar 2025 05:04:02 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.8.41</generator>
	<item>
		<title>Using jQuery UI&#8217;s AutoComplete with WCF</title>
		<link>http://www.bendewey.com/index.php/281/using-jquery-uis-autocomplete-with-wcf</link>
		<comments>http://www.bendewey.com/index.php/281/using-jquery-uis-autocomplete-with-wcf#comments</comments>
		<pubDate>Wed, 20 Oct 2010 02:04:43 +0000</pubDate>
		<dc:creator><![CDATA[bendewey]]></dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.bendewey.com/blog/?p=281</guid>
		<description><![CDATA[While experimenting with the new jQuery UI&#8217;s Autocomplete plugin, I discovered that the I couldn&#8217;t use the url source feature with a WCF service out.]]></description>
				<content:encoded><![CDATA[<p>While experimenting with the new jQuery UI&#8217;s Autocomplete plugin, I discovered that the I couldn&#8217;t use the url source feature with a WCF service out of the box as I expected.   With a few changes you can get really close, but when WCF serialized the JSON response they wrap it in a container object with the name <strong>&#8216;d&#8217;</strong>.  Luckily the Autocomplete plugin allows for <a href="http://jqueryui.com/demos/autocomplete/">three options </a>when specifying a source.  You can specify a javascript array, a string with a url that provides JSON, or a callback function which provides the a response parameter that you call with the filtered results.  The final option, a callback, is the one we will use when calling a WCF Service.  The simplest usage of the callback option (although rather usless) would be:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#Makes').autocomplete({
    source: function(request, response) {
       response(['test1', 'test2']);
    }
});
</pre>
<h3>WCF Service</h3>
<p>In order to get this working though we first need a WebScript enabled WCF Service.  To do so, you add a new WCF Service, we&#8217;ll call this on the AutomobileService.svc.  First thing is the setup the service to use WebScriptServiceHostFactory, open the actual .svc file (right click, Open With, OK) and add a new attribute with the Factory.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;%@ ServiceHost Language=&quot;C#&quot; Debug=&quot;true&quot; Service=&quot;jQueryAutocompleteWithWcf.AutomobileService&quot;
CodeBehind=&quot;AutomobileService.svc.cs&quot; Factory=&quot;System.ServiceModel.Activation.WebScriptServiceHostFactory&quot; %&gt;
</pre>
<p>Additionally, we want to add the WebGet attribute to the operations, which should have a single parameter for search &#8216;term&#8217;.</p>
<pre class="brush: csharp; title: ; notranslate">
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
IEnumerable&lt;string&gt; GetMakes(string term);
</pre>
<h3>Script and Markup</h3>
<p>Now that we have our service setup its time to call the WCF service.</p>
<pre class="brush: jscript; title: ; notranslate">
$('#Makes').autocomplete({
    source: function (request, response) {
        $.getJSON('AutomobileService.svc/GetMakes', request, function (data) {
            response(data.d);
        });
    }
});
</pre>
<p>Notice the response is using the data.d property where &#8216;d&#8217; is the WCF serialization container that caused us problems earlier.  With a few extra lines you can add caching and aborting.</p>
<pre class="brush: jscript; title: ; notranslate">
var makesCache = {}, makesXhr;
$('#Makes').autocomplete({
    source: function (request, response) {
        var term = request.term;
        if (term in makesCache) {
            response(makesCache[term]);
            return;
        }
        if (makesXhr != null) {
            makesXhr.abort();
        }
        makesXhr = $.getJSON('AutomobileService.svc/GetMakes', request, function (data, status, xhr) {
            makesCache[term] = data.d;
            if (xhr == makesXhr) {
                response(data.d);
                makesXhr = null;
            }
        });
    }
});
</pre>
<p>I hope this code help someone out in the future, the source code has a fully functional demo and should have all the code you need to get the WCF service returning results to your autocomplete textbox.  If you are interested in doing this with .NET 3.5 there are a few extra configuration items needed, leave a comment if you have any trouble and I&#8217;ll be happy to help out.</p>
<h3>Download</h3>
<p>The full source code is available for download from my website</p>
<ul>
<li><a href="http://www.bendewey.com/CodeBrowser/?zip=/code/jQueryAutocompleteWithWcf.zip" target="_blank">Browse Source Code (Requires Silverlight 4)</a></li>
<li><a href="http://www.bendewey.com/code/jQueryAutocompleteWithWcf.zip" target="_blank">jQueryAutocompleteWithWcf.zip (18kb)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bendewey.com/index.php/281/using-jquery-uis-autocomplete-with-wcf/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery FormatCurrency v1.4 released</title>
		<link>http://www.bendewey.com/index.php/261/jquery-formatcurrency-v1-4-released</link>
		<comments>http://www.bendewey.com/index.php/261/jquery-formatcurrency-v1-4-released#comments</comments>
		<pubDate>Thu, 24 Jun 2010 03:29:58 +0000</pubDate>
		<dc:creator><![CDATA[bendewey]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[formatcurrency]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.bendewey.com/blog/?p=261</guid>
		<description><![CDATA[I have updated the jQuery FormatCurrency plugin to work with jQuery 1.4.2 and the latest version of qUnit with  127 unit tests. Download http://jquery-formatcurrency.googlecode.com Release.]]></description>
				<content:encoded><![CDATA[<p>I have updated the jQuery FormatCurrency plugin to work with jQuery 1.4.2 and the latest version of qUnit with  127 unit tests.</p>
<h3>Download</h3>
<ul>
<li><a href="http://jquery-formatcurrency.googlecode.com">http://jquery-formatcurrency.googlecode.com</a></li>
</ul>
<h3>Release Notes</h3>
<ul>
<li>Fixed bug where &#8220;-&#8221; was deleted during Format As You Type.</li>
<li>Improved eventOnDecimalsEntered to only be triggered if necessary.</li>
<li>Improve Format As You Type demo by not calling formatCurrency on a SHIFT, CTRL, ALT, HOME or END key.</li>
<li>Added support for jQuery 1.4 and qUnit 1.4</li>
<li>Added fix and test for issue #19 &#8220;-.01&#8243; was formatting as &#8220;-$NaN.01&#8243;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bendewey.com/index.php/261/jquery-formatcurrency-v1-4-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building RIA Applications with jQuery and WCF</title>
		<link>http://www.bendewey.com/index.php/218/building-ria-apps-with-jquery-and-wcf</link>
		<comments>http://www.bendewey.com/index.php/218/building-ria-apps-with-jquery-and-wcf#comments</comments>
		<pubDate>Sun, 07 Mar 2010 18:20:47 +0000</pubDate>
		<dc:creator><![CDATA[bendewey]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.bendewey.com/blog/?p=218</guid>
		<description><![CDATA[I finished my jQuery and WCF presentation at the NYC Code Camp. Thanks to all that attended. Downloads I&#8217;ve uploaded the sample code and the.]]></description>
				<content:encoded><![CDATA[<p>I finished my jQuery and WCF presentation at the <a href="http://nyc.codecamp.us" target="_blank">NYC Code Camp</a>. Thanks to all that attended.</p>
<h3>Downloads</h3>
<p>I&#8217;ve uploaded the sample code and the presentation to my website.  You can use the following links to download them:</p>
<ul>
<li><a href="http://www.bendewey.com/downloads/codecamp/Building-RIA-with-jQuery.pptx" target="_blank">Building RIA Applications with WCF and jQuery Presentation (.pptx)</a></li>
<li><a href="http://www.bendewey.com/downloads/codecamp/jQuery-Demos.zip" target="_blank">Building RIA Applications with WCF and jQuery Samples (.zip)</a></li>
</ul>
<h3>Updates</h3>
<p>Since we had so many good questions, we didn&#8217;t have a chance to cover the delete feature.  I&#8217;ve included this in the sample source code along with some code comments related to how it was created.  Please feel free to post comments here if you have any questions.</p>
<h3>Disclaimer</h3>
<p>We briefly talked about the concept of RESTful web services.  Please note that our sample is missing a few components of REST webservice (ie. using the DELETE method, and proper URI templating).  For more information on building RESTful webservices see the slides and samples from my <a href="http://www.bendewey.com/blog/index.php/176/alt-net-rest-presentation">Alt.NET REST Presentation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bendewey.com/index.php/218/building-ria-apps-with-jquery-and-wcf/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery FormatCurrency v1.2 released</title>
		<link>http://www.bendewey.com/index.php/209/jquery-formatcurrency-v1-2-released</link>
		<comments>http://www.bendewey.com/index.php/209/jquery-formatcurrency-v1-2-released#comments</comments>
		<pubDate>Sat, 28 Nov 2009 17:33:29 +0000</pubDate>
		<dc:creator><![CDATA[bendewey]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[formatcurrency]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://bendewey.wordpress.com/?p=209</guid>
		<description><![CDATA[Last night I noticed a few issues added to the jQuery FormatCurrency page. I was able to resolve all of these issues and push out.]]></description>
				<content:encoded><![CDATA[<p>Last night I noticed a few issues added to the jQuery FormatCurrency page. I was able to resolve all of these issues and push out a new v1.2 release of the plugin.</p>
<h3>Download</h3>
<ul>
<li><a href="http://jquery-formatcurrency.googlecode.com">http://jquery-formatcurrency.googlecode.com</a></li>
</ul>
<h3>Release Notes</h3>
<ul>
<li>Stored originalDecimals for reporting on the decimalsEntered trigger</li>
<li>Added format_as_you_type demo page (from Emmanuel Sambo)</li>
<li>Fixed issue #11 blank should equal blank</li>
<li>Fixed bug #12 and added unit test (negativeFormatDecimal) to support</li>
<li>Fixed bug #13 and added a check for a float value</li>
<li>Fixed bug #14 and added unit tests for en-IN which contains edge cases due to its Rs. symbol (Rs. 1,000.00)</li>
</ul>
<h3>New Committer Added</h3>
<p>Additionaly, I&#8217;m happy to announce we&#8217;ve added a new committer to the team, Marco De Bortoli from Italy.  His contributions in bug reporting and fixing have already been valuable and we are looking forward to having him contribute to the futures.</p>
<h3>Creation of the Futures Page</h3>
<p>We&#8217;ve added a new Futures page to the Wiki.  This page will be used as a collaborative page to edit/comment on the future of the plugin.  The page can be found at <a href="http://code.google.com/p/jquery-formatcurrency/wiki/Futures">http://code.google.com/p/jquery-formatcurrency/wiki/Futures</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bendewey.com/index.php/209/jquery-formatcurrency-v1-2-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using JSONP with WCF and jQuery</title>
		<link>http://www.bendewey.com/index.php/186/using-jsonp-with-wcf-and-jquery</link>
		<comments>http://www.bendewey.com/index.php/186/using-jsonp-with-wcf-and-jquery#comments</comments>
		<pubDate>Tue, 24 Nov 2009 15:31:22 +0000</pubDate>
		<dc:creator><![CDATA[bendewey]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://bendewey.wordpress.com/?p=186</guid>
		<description><![CDATA[In the new release of .NET 4, the WCF team has added support for JSONP. There are many resource out on the internet about the.]]></description>
				<content:encoded><![CDATA[<p>In the new release of .NET 4, the WCF team has added support for <a href="http://en.wikipedia.org/wiki/JSON#JSONP">JSONP</a>.  There are many resource out on the internet about the need for JSONP, if you are reading this article I&#8217;m assuming your familar with the concept of JSONP.  Essentially, JSONP utilitzes the &lt;script /&gt; tag as a work around to the cross domain access limitations of web browsers.  This new feature is exposed as an CrossDomainScriptAccessEnabled setting on the WebHttpBinding, and as such is configurable through code or through configuration.</p>
<h3>Download</h3>
<p>The full source code is available for download from my website</p>
<ul>
<li><a href="http://www.bendewey.com/CodeBrowser/?zip=/code/JsonpWithWcfAndJquery.zip" target="_blank">Browse Source Code (Requires Silverlight 4)</a></li>
<li><a href="http://www.bendewey.com/code/JsonpWithWcfAndJquery.zip" target="_blank">JsonpWithWcfAndJquery.zip (46kb)</a></li>
</ul>
<p>This code requires the latest download of <a href="msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target="_blank">.NET 4 Beta 2 with Visual Studio 2010</a></p>
<h3>Example</h3>
<p>In this example we are returning a list of sample customers.  In a standard JSON service using the WebHttpBinding you would recieve this result:</p>
<p><a href="http://localhost:65025/CustomersService.svc/GetCustomers">http://localhost:65025/CustomersService.svc/GetCustomers</a></p>
<pre class="brush: jscript; title: ; notranslate">
[{&quot;Email&quot;:&quot;bob@example.com&quot;,&quot;Name&quot;:&quot;Bob&quot;},
{&quot;Email&quot;:&quot;mark@example.com&quot;,&quot;Name&quot;:&quot;Mark&quot;},
{&quot;Email&quot;:&quot;john@example.com&quot;,&quot;Name&quot;:&quot;John&quot;}]
</pre>
<p>Now using the same service you can supply the optional callback parameter like this <a href="http://localhost:65025/CustomersService.svc/GetCustomers">http://localhost:65025/CustomersService.svc/GetCustomers?callback=JsonpCallback</a>, which would return the results as the first argument to a function call with a name equal to the one supplied in the query parameter.</p>
<pre class="brush: jscript; title: ; notranslate">
JsonpCallback([{&quot;Email&quot;:&quot;bob@example.com&quot;,&quot;Name&quot;:&quot;Bob&quot;},
{&quot;Email&quot;:&quot;mark@example.com&quot;,&quot;Name&quot;:&quot;Mark&quot;},
{&quot;Email&quot;:&quot;john@example.com&quot;,&quot;Name&quot;:&quot;John&quot;}])</pre>
<p>So, if you have a javascript function setup on the page, the function will be called successfully without violating the cross-site scripting exceptions.</p>
<pre class="brush: jscript; title: ; notranslate">

function JsonpCallback(customers) {
     alert(cutomers.length);
}

</pre>
<h3>WCF Service with CrossDomainScriptAccessEnabled</h3>
<p>Creating the WCF Service with CrossDomainScriptAccessEnabled is the same as it would be for any other web enabled WCF service.  In our example we are exposing a simple CustomersService</p>
<pre class="brush: csharp; title: ; notranslate">
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CustomersService
{
    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public List GetCustomers()
    {
        return Customer.GetSampleData().ToList();
    }
}</pre>
<p>The new JSONP feature is exposed via the WebHttpBinding.  The configuration for the CustomersService would looks like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;system.serviceModel&gt;
  &lt;behaviors&gt;
    &lt;endpointBehaviors&gt;
      &lt;behavior name=&quot;webHttpBehavior&quot;&gt;
        &lt;webHttp /&gt;
      &lt;/behavior&gt;
    &lt;/endpointBehaviors&gt;
  &lt;/behaviors&gt;
  &lt;bindings&gt;
    &lt;webHttpBinding&gt;
      &lt;binding name=&quot;webHttpBindingWithJsonP&quot; crossDomainScriptAccessEnabled=&quot;true&quot; /&gt;
    &lt;/webHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;services&gt;
    &lt;service name=&quot;ServiceSite.CustomersService&quot;&gt;
      &lt;endpoint address=&quot;&quot; binding=&quot;webHttpBinding&quot;
                bindingConfiguration=&quot;webHttpBindingWithJsonP&quot;
                contract=&quot;ServiceSite.CustomersService&quot;
                behaviorConfiguration=&quot;webHttpBehavior&quot;/&gt;
    &lt;/service&gt;
  &lt;/services&gt;
&lt;/system.serviceModel&gt;</pre>
<p>Notice that we&#8217;ve created a new bindingConfiguration for webHttpBindingWithJsonP, in this new binding configuration we&#8217;ve set the new property of crossDomainScriptAccessEnabled to true.  This enables the new callback parameter and under the covers attaches the JavascriptCallbackMessageInspector.  I&#8217;ve choosen to explicitly setup my binding configuration, but it should be noted that .NET 4 has created default configuration features, a sample of this is available for download with the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=35ec8682-d5fd-4bc3-a51a-d8ad115a8792&amp;displaylang=en" target="_blank">WCF Samples for .NET 4 Beta2</a>.</p>
<h3>Consuming JSONP with jQuery</h3>
<p>Now, consuming this JSONP endpoint with jQuery couldn&#8217;t be easier.  jQuery ships with an <a href="http://docs.jquery.com/Ajax/jQuery.ajax" target="_blank">ajax</a> convenience function called <a href="http://docs.jquery.com/Ajax/jQuery.getJSON" target="_blank">getJSON</a> that accepts a url, data, and a callback function.  In the url property you can provide a ? following a query parameter and the ajax function will replace it with a dynamic function to handle the JSONP callback.  With that being said this is what the code to access the customers would look like.</p>
<pre class="brush: jscript; title: ; notranslate">
// Get the JsonP data
$.getJSON('http://localhost:65025/CustomersService.svc/GetCustomers?callback=?', null, function (customers) {
    alert('Received ' + customers.length + ' Customers');
});</pre>
<h3>Conclusion</h3>
<p>Many of the code samples above use an abridged version of the code in the sample, so for more detail you should download the source code above.  Additionally this article and samples are based on the .NET 4 Beta 2 product.  I&#8217;ll do my best to update the code and ensure everything is in order with the official release.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bendewey.com/index.php/186/using-jsonp-with-wcf-and-jquery/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>LitWare Training sample application now available on MSDN Code Gallery</title>
		<link>http://www.bendewey.com/index.php/147/litware-training</link>
		<comments>http://www.bendewey.com/index.php/147/litware-training#comments</comments>
		<pubDate>Fri, 17 Jul 2009 02:43:28 +0000</pubDate>
		<dc:creator><![CDATA[bendewey]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Litware Training]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[wcf rest starter kit]]></category>

		<guid isPermaLink="false">http://bendewey.wordpress.com/?p=147</guid>
		<description><![CDATA[The WCF Team at Microsoft just posted their LitWare Training sample application (http://code.msdn.microsoft.com/litwaremashup) on the MSDN Code Gallery website.   The Litware Training application is a sample application using WCF.]]></description>
				<content:encoded><![CDATA[<p>The WCF Team at Microsoft just posted their LitWare Training sample application (<a href="http://code.msdn.microsoft.com/litwaremashup">http://code.msdn.microsoft.com/litwaremashup</a>) on the MSDN Code Gallery website.   The Litware Training application is a sample application using WCF and the WCF REST Starter Kit to build a “Mashup” web site.  LitWare Training is a fictitious training company that maintains registration for technical training courses.  The main selling point for this fictitious company is that it provides a rich, integrated user experience by incorporating multiple services that exist on the internet. </p>
<img title="Litware Training Screenshot" src="http://bendewey.files.wordpress.com/2009/07/litware.png" alt="Litware Training Screenshot" width="300" height="196" />
<p>This sample application includes more products and services mashed together than any other application that I&#8217;ve seen.  Among the many services and products featured in this application are:</p>
<ul>
<li>ASP.NET</li>
<li>Windows Communication Foundation (WCF)</li>
<li>WCF REST Starter Kit Preview 2</li>
<li>SQL Server 2008</li>
<li>Entity Framework</li>
<li>Unity</li>
<li>jQuery with AJAX</li>
<li>Silverlight</li>
<li>Virtual Earth</li>
<li>Live Search</li>
<li>Twitter</li>
<li>Facebook</li>
<li>Amazon</li>
<li>ATOM/RSS Feeds Viewer</li>
</ul>
<p>At twentysix New York I worked very closely with Kent Brown from Microsoft on this reference application.  Please download the code, take a look, and leave me feedback on this blog if you have any questions.  Additionally, I will be producing a series of screencasts reviewing and demonstrating this application.  Please stay tuned to my blog for updates and links when those screencasts get posted.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bendewey.com/index.php/147/litware-training/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Updated jQuery formatCurrency plugin posted on GoogleCode</title>
		<link>http://www.bendewey.com/index.php/128/updated-jquery-formatcurrency-plugin-posted-on-googlecode</link>
		<comments>http://www.bendewey.com/index.php/128/updated-jquery-formatcurrency-plugin-posted-on-googlecode#comments</comments>
		<pubDate>Wed, 27 May 2009 02:00:18 +0000</pubDate>
		<dc:creator><![CDATA[bendewey]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[formatcurrency]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://bendewey.wordpress.com/?p=128</guid>
		<description><![CDATA[After receiving some comments on my formatCurrency plugin regarding international support I decided to create an official release of the formatCurrency jQuery plugin. The new.]]></description>
				<content:encoded><![CDATA[<p>After receiving some comments on my <a href="http://bendewey.wordpress.com/2008/11/11/jquery-formatcurrency-plugin">formatCurrency plugin</a> regarding international support I decided to create an official release of the formatCurrency jQuery plugin.</p>
<p>The new plugin is available on the Google Code at <a href="http://jquery-formatcurrency.googlecode.com">http://jquery-formatcurrency.googlecode.com</a>.</p>
<p>Thank you to everyone on for your downloads and comments. Please contact me if you are interested in becoming a member on the project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bendewey.com/index.php/128/updated-jquery-formatcurrency-plugin-posted-on-googlecode/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create SendAsync Convenience Extensions for the WCF REST HttpClient to GetAsync and PostAsync</title>
		<link>http://www.bendewey.com/index.php/96/httpclient-send-async-convenience-extension</link>
		<comments>http://www.bendewey.com/index.php/96/httpclient-send-async-convenience-extension#comments</comments>
		<pubDate>Wed, 20 May 2009 19:18:38 +0000</pubDate>
		<dc:creator><![CDATA[bendewey]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://bendewey.wordpress.com/?p=96</guid>
		<description><![CDATA[I recently had the pleasure of speaking with some industry icons. We compared some RESTful jQuery code with the new HttpClient code from the WCF.]]></description>
				<content:encoded><![CDATA[<p>I recently had the pleasure of speaking with some industry icons. We compared some RESTful jQuery code with the new HttpClient code from the <a href="http://go.microsoft.com/?linkid=9653247" target="_blank">WCF Rest Starter Kit Preview 2</a>.  The line by line comparison on the code was quite similar (the WCF REST team has done an excellent job with this API, I&#8217;m always amazed at how easy it is to use),  the main difference was that the jQuery code was transmitting asynchronously.  After our conversation, I decided to create these convenience extensions to give developers an API for using lambda expressions to call RESTful services asynchronously in .NET.</p>
<h3>Download</h3>
<p>In this application I use the jQuery code from my <a href="http://bendewey.wordpress.com/2009/02/09/introduction-to-jquery-presentation/">Intro to jQuery presentation</a> and the <a href="http://bendewey.wordpress.com/2009/03/14/connecting-to-live-search-using-the-httpclient/">Live Search WPF Application</a>.   The first method I wrote was the GetAsync extension, and after realizing how simple it was I created this entire Extension Library.  Additionally, since all the code fit nicely into a single class I&#8217;m going to publish the code as a single cs file.  As usual, I&#8217;m also including the Sample application for download.</p>
<p><a href="http://www.bendewey.com/code/HttpAsyncMethodExtensions.cs.txt" target="_blank">HttpAsyncMethodExtensions.cs (12.1KB)</a></p>
<p><a href="http://www.bendewey.com/code/HttpClientExtension.zip" target="_blank">HttpClientExtensions Sample WPF Application (Compressed Zip, 13.1KB)</a></p>
<h3>Code Comparison</h3>
<p>The goal of this API was to mimic the jQuery AJAX code that I had previously written.  Here is a actual ajax portion of the jQuery code that retrieves some google search results:</p>
<pre class="brush: jscript; title: ; notranslate">$(document).ready(function() {
	$('.getGoogle').click(function(e) {
		//  Prevent the event and Set Loading Message
		e.preventDefault();
		$('.results .noResults').html('Loading...');

		// Generate the google Url
		var googleUri = &quot;http://www.google.com/search?q=&quot; + $('.searchText').val();

		// Send Async GET call
		$.get(googleUri, {}, function(html) {

			// Parse result and create placeholder
			var google = $(html);
			var ul = $('&lt;ul /&gt;');

			// find links from results
			$('.g .r .l', google).each(function() {

				// create the list item, generate the list item, and add it to the placeholder
				ul.append($('&lt;li /&gt;')
					.append($(this).clone().removeAttr('onmousedown')) // this.clone() clones the google link
				);
			});

			$('.results').append(ul).find('.noResults').remove();
		});
	});
});</pre>
<p>Using this jQuery code as a guide I created the usage code first:</p>
<pre class="brush: csharp; title: ; notranslate">private void Search_Click(object sender, RoutedEventArgs e)
{
	// Set Loading Message
	this.Items.Clear();
	this.Items.Add(&quot;Loading ...&quot;);

	// Generate Google Uri
	const string googleApiUrl = &quot;http://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;q={0}&quot;;
	var uri = string.Format(googleApiUrl, this.SearchText.Text);

	// Create Client and Send Asynchronous GET
	var client = new HttpClient();
	client.GetAsync(uri, (s, r) =&gt;
	{
		// Clear Loading Message
		this.Items.Clear();

		// Parse Results
		var results = r.Response.Content.ReadAsJsonDataContract&lt;googleResults&gt;();

		// Find and add the results
		this.Items.AddRange(results.responseData.results.Cast&lt;object&gt;());
	});
}</pre>
<p>I tried to keep the two samples consistent, and as you can see the HttpClient code is 5 lines smaller than its jQuery counterpart.  Unfortunately, these samples are not identical implementations.  For instance, one client is a web browser and the other is a WPF application.  Additionally, both projects have additional code, behind the scenes.  But since the goal was to create a similar API I think it works.</p>
<h3>HttpClient Extension Methods</h3>
<p>What you may not know, is that the HttpClient gains most of its leverage from extension methods. The core functionality of the HttpClient is in its Send method.  In the existing API, the Get, Post, Put, Delete methods are extension methods which simple call Send.  Using that same concept, here is a GetAsync extension method to the HttpClient:</p>
<pre class="brush: csharp; title: ; notranslate">public static class HttpAsyncMethodExtensions
{
	public static void GetAsync(this HttpClient client, string uri, EventHandler&lt;sendCompletedEventArgs&gt; completed)
	{
		// register callback
		client.SendCompleted += completed;

		// call SendAsync
		var message = new HttpRequestMessage(HttpMethod.GET.ToString(), uri);
		client.SendAsync(message);
	}
}</pre>
<p>The HttpClientAsyncExtensions Library, that is downloadable above, contains the full implementation of these extension methods for SendAsync, GetAsync, PostAsync, PutAsync, DeleteAsync, and HeadAsync.  There are also a few overloaded helper methods to avoid repeating code.</p>
<h3>Conclusion</h3>
<p>I think its great that we have the ability to choose between synchronous and asynchronous processing of remote calls.  Unfortunately, the amount of code required to perform these tasks is often quite different.</p>
<p>We&#8217;ve all seen applications that block the UI thread while executing a long running task synchronously.  I&#8217;m not sure if this is because of the tools or because of a lack of knowledge around asynchronous programming.  Either way, developers often feel that asynchronous programming is difficult.</p>
<p>I&#8217;m hoping that these extension methods will show that this doesn&#8217;t have to be the case, and that we can actually make remote services calls asynchronously with very little code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bendewey.com/index.php/96/httpclient-send-async-convenience-extension/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introduction to jQuery Presentation</title>
		<link>http://www.bendewey.com/index.php/59/introduction-to-jquery-presentation</link>
		<comments>http://www.bendewey.com/index.php/59/introduction-to-jquery-presentation#comments</comments>
		<pubDate>Tue, 10 Feb 2009 04:07:14 +0000</pubDate>
		<dc:creator><![CDATA[bendewey]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Presentations]]></category>

		<guid isPermaLink="false">http://bendewey.wordpress.com/?p=59</guid>
		<description><![CDATA[I just finished my Introduction to jQuery presentation at the NYC Web Design Meetup.  Thanks for all that attended.  We had a really good time.]]></description>
				<content:encoded><![CDATA[<p>I just finished my Introduction to jQuery presentation at the <a href="http://www.meetup.com/nyc-web-design" target="_self">NYC Web Design Meetup</a>.  Thanks for all that attended.  We had a really good time and had lots of great questions.</p>
<h3>Download</h3>
<p>I&#8217;ve posted the presentation and demos online.</p>
<p><a class="skyd_embd_dlnk" href="http://cid-473151cb8afe66ba.skydrive.live.com/self.aspx/.Public/Presentations/Intro to jQuery.zip" target="_top">Intro to jQuery.zip</a></p>
<h3>Note</h3>
<p>I made some minor changes to the Google AJAX sample.  The sample shown at the meeting didn&#8217;t support repeated clicks of the Get Google Links button.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bendewey.com/index.php/59/introduction-to-jquery-presentation/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>jQuery Tab View using AJAX and WCF REST Service</title>
		<link>http://www.bendewey.com/index.php/31/jquery-tab-view-using-ajax-and-wcf-rest-service</link>
		<comments>http://www.bendewey.com/index.php/31/jquery-tab-view-using-ajax-and-wcf-rest-service#comments</comments>
		<pubDate>Wed, 04 Feb 2009 18:31:34 +0000</pubDate>
		<dc:creator><![CDATA[bendewey]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://bendewey.wordpress.com/?p=31</guid>
		<description><![CDATA[In response to a question on StackOverflow Master Details using jQuery Tabs I wrote little sample app to demonstrate using jQuery Tabs and a WCF.]]></description>
				<content:encoded><![CDATA[<p>In response to a question on StackOverflow <a href="http://stackoverflow.com/questions/509287/master-details-using-jquery-tabs">Master Details using jQuery Tabs</a> I wrote little sample app to demonstrate using jQuery Tabs and a WCF REST Service to create a Master Details view of Orders. I decided I&#8217;d also reference the solution here and give a little bit of an overview of how the Sample works.</p>
<h3>Download</h3>
<p>Sample Project: <a href="http://www.bendewey.com/code/jQuery-AjaxTabView-Sample.zip" target="_blank">jQuery-AjaxTabView-Sample.zip</a> (194KB)</p>
<h3>Default.aspx</h3>
<p>The Default page is basically a UI Tab setup with a ListView on the first tab.  The ListView contains a table of Orders with a simple Select link.  Notice that the select button is not an asp hyperlink control.  If you don&#8217;t need the extra code-behind or rendering of the user control I avoid them.  But, back to the Default Page.  On the second tab I have to layers one for loading and one for results.  The results tab is preloaded with the default message of Select an order.</p>
<p>The other major function of the page is in the jQuery Scripting, but I&#8217;ll get into that later.  First let me explain the service.</p>
<h3>WCF Orders Service</h3>
<p>With the release of the <a href="http://msdn.microsoft.com/en-us/netframework/cc950529.aspx" target="_blank">WCF REST Starter Kit</a> its become very simple to create a service that returns some simple JSON results.   In this sample I have a single service called Service.svc (OrderService might have been a better name, next time&#8230;).  The service has a standard WebServiceHost2 Factory definition (which you can view by opening the actual Service.svc file) and a single Service.svc.cs code-behind.  The Service contains two methods one to return all Orders and one to return a single Order&#8217;s Details</p>
<pre><pre class="brush: csharp; title: ; notranslate">
[ServiceContract]
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class OrderDetailsService
{
    [OperationContract]
    [WebGet(UriTemplate = &quot;&quot;, ResponseFormat = WebMessageFormat.Json)]
    public IEnumerable GetOrders()
    {
        // todo: replace with real implementation
        return Order.GetStubData();
    }

    [OperationContract]
    [WebGet(UriTemplate = &quot;{orderId}&quot;, ResponseFormat = WebMessageFormat.Json)]
    public List GetOrderDetails(string orderId)
    {
        // todo: replace with real implementation
        var orders = Order.GetStubData();

        // todo: handle bad orderIds
        var order = orders.FirstOrDefault(o =&gt; o.OrderId == int.Parse(orderId));

        if (order == null)
            return null;

        return order.Details;
    }
}
</pre>
<p>You can access <a href="http://localhost:55555/Service.svc">http://localhost:{port}/Service.svc</a> to get the Orders as a JSON list, or you can access <a href="http://localhost:55555/Service.svc/1">http://localhost:{port}/Service.svc/1</a> to get the OrderDetails as a JSON list for Order #1.</p>
<h3>jQuery Scripts</h3>
<p>Now that you have the WCF Service setup you need to have jquery connect to the service and render the data out when it receives the results.  The basic steps are that occur when the Select button is clicked are:</p>
<ol>
<li>Call preventDefault to stop the link</li>
<li>Update the Tab2 UI to Loading</li>
<li>Select Tab 2</li>
<li>Parse the OrderId from the Hash of the link</li>
<li>call jQuery $.getJSON(&#8216;Service.svc/{orderId}&#8217;, null, function(json) {  } );</li>
</ol>
<p>When the you return from the getJSON call you need to:</p>
<ol>
<li>Check to determine that you got valid results</li>
<li>Set error message if necessary</li>
<li>Generate table of results</li>
<li>Loop results creating a row for each result</li>
<li>Reset UI to hide loading and show results</li>
</ol>
<p>Now on to the actual script that handles this.  Keep in mind that all this code is inside a $(document).ready(), for the full implementation download the sample project.</p>
<pre><pre class="brush: jscript; title: ; notranslate">
$('.selectOrder').click(function(e) {
    e.preventDefault();

    //setup loading ui
    $('#tabs').tabs('select', 1);
    $('#tabs-2 .loading').show();
    $('#tabs-2 .results').hide().empty();

    var id = this.hash.replace(&quot;#Select_&quot;, &quot;&quot;)

    $.getJSON(&quot;Service.svc/&quot; + id, null, function(details) {
        details.length = details.length ? details.length : 0;
        if (details.length == 0) {
            $('#tabs-2 .results').append('&lt;h3&gt;No Order Details&lt;/h3&gt;').show();
        }
        else {
            var table = $('&lt;table /&gt;').attr('cellspacing', 0).attr('cellpadding', 4);

            var header = $(&lt;tr /&gt;')
                .appendCell(&quot;Product&quot;)
                .appendCell(&quot;Quantity&quot;)
                .appendCell(&quot;Price&quot;)
                .appendCell(&quot;Cost&quot;)
                .addClass('header');
            table.append(header);

            $.each(details, function() {
                var row = $('&lt;tr /&gt;')
                    .appendCell(this.Product)
                    .appendCell(this.Quantity)
                    .appendCell(this.Price)
                    .appendCell(this.Quantity*this.Price);
                table.append(row);
            });

            $('#tabs-2 .results').append(table).show();
        }

        $('#tabs-2 .loading').hide();
    });
});
</pre>
<h3>Conculsion</h3>
<p>I hope that you like this sample.  As with any full AJAX solution the real complication comes into play when we start trying to customize the design.  That being said I would recommend putting as much of the design into the css as possible and avoid putting to many styles in the javascript. </p>
<p>Other things to note, this doesn&#8217;t work cross domain, in order to do cross-domain json you need to use jsonp (JSON with Padding).   JSONP can be accomplished through the use of WCF Extensions which is not covered in this article, for more information see this <a title="JSON with Padding (AJAX)" href="http://msdn.microsoft.com/en-us/library/cc716898.aspx" target="_blank">msdn article</a> and this <a title="feedback on the json with padding implementation" href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/eb559c61-d512-4692-aaa1-2c3656c78e49/" target="_self">msdn forum post</a>.  jQuery supports jsonp; you would change the getJSON call to $.getJSON(&#8216;Service.svc/1?callback=?&#8217;), where callback is the name of the querystring parameter expected by the service, and jquery would recongnize the callback=? and handle all the dirty work for you.  Finally, there is no exception handling in this code.  I just set the length to 0 if I don&#8217;t find one.  WCF will actually return the Exception message in the json response.  The next iteration of this project would be to include exception handling in the results callback. </p>
<p>Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bendewey.com/index.php/31/jquery-tab-view-using-ajax-and-wcf-rest-service/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
