Monday, May 23, 2011

SharePoint 2010 and .Net 4 Part 2

A continuation from this post.

I have achieved a managed software development cycle for complex SharePoint 2010 systems, a brief overview (albeit poorly drawn sample)

I have had several problems before finalizing the solution & project files:

  1. SharePoint 2010 application pool can only support .Net 3.5 and below (our latest proprietary framework is done with .Net 4.0)
  2. Cross-Origin Request Sharing 
  3. SharePoint 2010 requires signed assemblies for Visual Webpart projects in order to do debugging

For the first problem, we have worked around by wrapping the Business Interface with a WCF project that acts as a proxy. We had a lot of internal arguments, discussions and some conflict on this approach. One of the team member is uncomfortable with the additional overhead, however after doing several tests with Apache Bench, we are satisfied with the performance and delays. Another colleague actually done a similar implementation and mentioned that in the long-run when user base increases, we can actually scale out by letting the WCF services run on a dedicated box, sounds nice. Thus, we went ahead with the WCF as a proxy pattern. 

For the second problem, we spent many man hours figuring out why we can't do an AJAX call to our custom WCF services via jQuery 1.6. After narrowing down the issues to the Cross-Origin Request Sharing, we have tried to use JSONP without success, setting jQuery options of $.support.cors = true without success, jQuery options of CrossDomain = true without success. I spent few hours trying to make the jQuery call the WCF, something which appears so simple and straight forward, i decided to use google chrome and see what the console says..

"XMLHttpRequest cannot load <url>. Origin <url> is not allowed by Access-Control-Allow-Origin." We fixed the issue by adding a global.asax into the WCF project and adding a method in the Application_BeginRequest.

protected void Application_BeginRequest(object sender, EventArgs e)
{
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
    if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
    {
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods",  "GET, POST");

        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");

        HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
        HttpContext.Current.Response.End();
    }
}

For the third problem, it wasn't so bad, we just had to get the framework team to sign all their libraries before we add into SharePoint bin. This is actually for non Visual Webpart solutions, namely sharepoint application pages. We would have to use our Business Objects and Interfaces on the codebehind, so that pretty much explains it.

Have fun developing in SharePoint 2010 :)

No comments:

Post a Comment