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 :)

Thursday, May 12, 2011

SharePoint 2010 and .Net 4

There are many people that tried and failed (including myself), my company have a proprietary framework written in .Net 4.0 (latest release), after 3 frustrating days and nights, i've given up and made several work-arounds and exceptions.

The only way that allow you to use .Net 4 projects is, to wrap it around a WCF 3.5 project. My solution for the current project involves jQuery and WCF heavily in order to give the end users a highly interactive interface. Hope to be able to extract non-sensitive snippets and post it here.

Wednesday, May 11, 2011

Fix iPhone vibration problems

My iPhone 3GS vibration motor just went dead on me for no reason, luckily I have an app called iBrate, after double tapping on the screen which supposedly made the phone vibrate non stop, it's still not budging, in a fit of anger I hit it on my table and the thing went bzzzzzzzzzzzz. Caught me by surprise, after googling for similar cases, I found that using iBrate with slapping the phone's back on the palm is a solution for many. Guess it's time to get iPhone 5 as soon as it launches :)

Thursday, May 5, 2011

SharePoint 2010 custom error off

Back in MOSS 2007, when i need to debug, all i have to do is to change the web.config file:

<customErrors mode="Off"/>

However, in SharePoint 2010, there is another web.config in the Hive folder, under LAYOUTS. To disable customError, remember to give hive folder a visit and change the values there :)