I’ve Changed Domains

Thank you to all my readers up until this point. I’ve decided to move my domain over to the open source WordPress.org. From now on I will be hosting my blog at my personal website.

http://www.bendewey.com/blog

I look forward to many more blog posts at my new home.

jQuery FormatCurrency v1.2 released

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.

Download

Release Notes

  • Stored originalDecimals for reporting on the decimalsEntered trigger
  • Added format_as_you_type demo page (from Emmanuel Sambo)
  • Fixed issue #11 blank should equal blank
  • Fixed bug #12 and added unit test (negativeFormatDecimal) to support
  • Fixed bug #13 and added a check for a float value
  • Fixed bug #14 and added unit tests for en-IN which contains edge cases due to its Rs. symbol (Rs. 1,000.00)

New Committer Added

Additionaly, I’m happy to announce we’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.

Creation of the Futures Page

We’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 http://code.google.com/p/jquery-formatcurrency/wiki/Futures.

Using JSONP with WCF and jQuery

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 need for JSONP, if you are reading this article I’m assuming your familar with the concept of JSONP.  Essentially, JSONP utilitzes the <script /> 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.

Download

The full source code is available for download from my website

This code requires the latest download of .NET 4 Beta 2 with Visual Studio 2010

Example

In this example we are returning a list of sample customers.  In a standard JSON service using the WebHttpBinding you would recieve this result:

http://localhost:65025/CustomersService.svc/GetCustomers

[{"Email":"bob@example.com","Name":"Bob"},
{"Email":"mark@example.com","Name":"Mark"},
{"Email":"john@example.com","Name":"John"}]

Now using the same service you can supply the optional callback parameter like this http://localhost:65025/CustomersService.svc/GetCustomers?callback=JsonpCallback, 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.

JsonpCallback([{"Email":"bob@example.com","Name":"Bob"},
{"Email":"mark@example.com","Name":"Mark"},
{"Email":"john@example.com","Name":"John"}])

So, if you have a javascript function setup on the page, the function will be called successfully without violating the cross-site scripting exceptions.


function JsonpCallback(customers) {
     alert(cutomers.length);
}

WCF Service with CrossDomainScriptAccessEnabled

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

[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CustomersService
{
    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public List GetCustomers()
    {
        return Customer.GetSampleData().ToList();
    }
}

The new JSONP feature is exposed via the WebHttpBinding.  The configuration for the CustomersService would looks like this:

<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="webHttpBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <bindings>
    <webHttpBinding>
      <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
    </webHttpBinding>
  </bindings>
  <services>
    <service name="ServiceSite.CustomersService">
      <endpoint address="" binding="webHttpBinding"
                bindingConfiguration="webHttpBindingWithJsonP"
                contract="ServiceSite.CustomersService"
                behaviorConfiguration="webHttpBehavior"/>
    </service>
  </services>
</system.serviceModel>

Notice that we’ve created a new bindingConfiguration for webHttpBindingWithJsonP, in this new binding configuration we’ve set the new property of crossDomainScriptAccessEnabled to true.  This enables the new callback parameter and under the covers attaches the JavascriptCallbackMessageInspector.  I’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 WCF Samples for .NET 4 Beta2.

Consuming JSONP with jQuery

Now, consuming this JSONP endpoint with jQuery couldn’t be easier.  jQuery ships with an ajax convenience function called getJSON 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.

// Get the JsonP data
$.getJSON('http://localhost:65025/CustomersService.svc/GetCustomers?callback=?', null, function (customers) {
    alert('Received ' + customers.length + ' Customers');
});

Conclusion

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’ll do my best to update the code and ensure everything is in order with the official release.

ALT.NET REST Presentation

I just finished my REST presentation at the NYC ALT.NET Meetup. Thanks to all that attended.  Unfortunately I didn’t get through all my samples, but I’m happy to have quality discussion. 

Downloads

I’ve uploaded the sample code and the presentation to my website.  You can use the following links to download them:

Links

As I noted in the resources section of my presentation the following links may be of interest.

RESTful .NET

Above all I’d like to give a lot of credit to Jon Flanders. If it were not for his book this presentation would not have been possible. To anyone who is interested in learning about REST in .NET his book is a must read.

Should you use Stored Procedures with LINQ?

I’ve had the discussion many times about whether or not to use Stored Procedures when consuming my LINQ to SQL or Entity Framework models.  I think that Lenni has come up with an excellent compromise in his Rethinking the Dynamic SQL vs. Stored Procedure Debate with LINQ blog post. 

Basically, he thinks we use LINQ for SELECT operations, harnessing Dynamic SQL, and continue to use Stored Procedures for the INSERT, UPDATE and DELETE operations.

Lenni is a SQL Server guru who basically wrote the book on Programming SQL Server.  His deep analysis of the debate is spot on.  Although, I still strive to use full capabilities of the ORM; I can see the need for maintaining  control of the data manipulation using Stored Procedures.  Also, since you’re often writing way less than half as much data as you’re reading, you shouldn’t see a any real performance decrease for not utilizing a partial UPDATE statement.  I hope this will encourage the strict DBAs to allow more dynamic SQL into the DB.

Apache Stonehenge Interoperability Presentation at the NYC .NET Dev User Group

I just finished my Apache Stonehenge interoperability demo at the NYC .NET Developer’s User Group meeting. Thanks to all that attended, we had a great time and some really good questions. Hopefully I’ve sparked some interested in the community about interoperability and the ability to connect multiple languages and platforms together using web services and WCF.

Downloads

As promised the slides from this evening’s presentation are available for download on my website.  If your downloading the slides please join the mailing list and let us know what you think.

http://www.bendewey.com/downloads/Apache-Stonehenge.pptx

Links

Also here are some of the key links from my presentation

LitWare Training sample application now available on MSDN Code Gallery

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 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. 

Litware Training Screenshot

This sample application includes more products and services mashed together than any other application that I’ve seen.  Among the many services and products featured in this application are:

  • ASP.NET
  • Windows Communication Foundation (WCF)
  • WCF REST Starter Kit Preview 2
  • SQL Server 2008
  • Entity Framework
  • Unity
  • jQuery with AJAX
  • Silverlight
  • Virtual Earth
  • Live Search
  • Twitter
  • Facebook
  • Amazon
  • ATOM/RSS Feeds Viewer

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.

Project StoneHenge Podcast from the ConnectedShow

The ConnectedShow podcast is a new podcast created to help Developers get up to speed with .NET technologies.  They just recently posted an episode related to Project Stonehenge, a project I’ve been working with recently.

ConnectedShow Podcast #8: Project Stonehenge

http://www.connectedshow.com/default.aspx?Episode=8

Keep up the good work Dimitry and Peter

Microsoft and Sun commit to support WS-* standards by building interoperating reference applications under “Project Stonehenge”

At the JavaOne conference on June 4, Dan’l Lewin and Steven Martin from Microsoft appeared for the keynote to announce their further support of Interoperability. This effort is backed by Sun joining the Apache Stonehenge Incubator project. Stonehenge is sponsored by the Apache Software Foundation, a leader in the Open Source community, and was created to build reference applications that demonstrate the use of WS-* Standards in real-world project implementations.

This came at a great time,  the StoneHenge project just completed their M1 release of the StockTrader application.  M1 comes complete with installation guides and interoperability walkthroughs for connecting .NET, PHP, and WSO2’s Web Service Application Server (WSAS), a Java implementation.

The Sun Metro implementation discussed at JavaOne is currently contributed to the project.  Additionally, there is a patch available for the .NET stack that supports this Metro implementation.  The commiters at Stonehenge hope to have the Metro Implemetation added to trunk by the M2 release.

This is really good news, as I mentioned in my previous post, I’ve recently been contributing to the StockTrader application.  This announcement in some ways confirms the success and commitment to open standards and interoperability in enterprise environments.  Although, the real success and adoption is now in the hands of the Open Source community.  That being said, I’d like to take this opportunity to once again encourage developers to take a look at the Apache Stonehenge project, download the bits, and offer feedback and support.

Updated jQuery formatCurrency plugin posted on GoogleCode

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 plugin is available on the Google Code at http://jquery-formatcurrency.googlecode.com.

Thank you to everyone on for your downloads and comments. Please contact me if you are interested in becoming a member on the project.