Section9

To content | To menu | To search

Tag - Development

Entries feed - Comments feed

Wednesday 2 September 2009

Wake Up SharePoint Sites on multiple Front Ends

So, you have multiple Front Ends behind a Load Balancer and you want to wake up each front end to enable the content to be served as fast as possible. 
Here is a small architecture with 3 Front Ends (click to zoom):
  SharePoint Architecture 
Front End A: 10.0.0.1 
Front End B: 10.0.0.2 
Front End C: 10.0.0.3 
Each Front Ends will respond to http://intranet.fabrikam.com because their IIS Host Headers are configured to “intranet.fabrikam.com”, but if you use this URL its the “Load Balancer” which is going to reply. 
So, How can you access http://intranet.fabrikam.com on Front End A ? 
You have to send the HTTP Request to the Front End A’s IP Address (10.0.0.1) using “intranet.fabrikam.com” as the host value in the HTTP Request. 
Here is the HTTP Request you must build to access http://intranet.fabrika.com :
GET / HTTP/1.1 
Accept: application/x-ms-application, */*
Accept-Language: en,fr-BE;q=0.5
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729
Accept-Encoding: gzip, deflate
Host: intranet.fabrikam.com
Connection: Keep-Alive
Then you have to send it to Front End A’s IP Address (10.0.0.1)  How to send that request to that IP Address ? There are many ways to do that:
  1. Using System.Net.Sockets.Socket
  2. Using WebClient or WebRequest (method A)
  3. Using WebClient or WebRequest (method B)
First Method (Using System.Net.Sockets.Socket): 
There is a major drawback with this method, you’ll have to handle authentication manually (easy with Basic Authentication, pretty hard with Ntlm or Kerberos)  

 1
2
3
4
5
6
7
8
9
10
11
12
13
string strHttpRequest = String.Concat("GET / HTTP/1.1rn", "Accept: application/x-ms-application, */*rn", "Accept-Language: en,fr-BE;q=0.5rn", "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729rn", "Accept-Encoding: gzip, deflatern", "Host: intranet.fabrikam.comrn", "Connection: Keep-Alivernrn"); //Create a IPv4 TCP Socket 
Socket socketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//Connect to the Front End A's IP address on HTTP Port (80) 
socketClient.Connect(IPAddress.Parse("10.0.0.1"), 80);
//Send the Http Request 
socketClient.Send(Encoding.Default.GetBytes(strHttpRequest));
StringBuilder sbHttpResponse = new StringBuilder();
byte[] bReceiveBuffer = new byte[4096]; int iReceivedBytes = 0;
//Process the Http Response 
while ((iReceivedBytes = socketClient.Receive(bReceiveBuffer)) > 0)
sbHttpResponse.Append(Encoding.Default.GetString(bReceiveBuffer, 0, iReceivedBytes));
//Output the Http Response 
Console.WriteLine(sbHttpResponse.ToString());

Second Method (Using WebClient or WebRequest (method A)):
 
Apparently this method will only work with .NET FrameWork 4.0, actually it doesn't (.NET 3.5) because you cannot alter the “Host” header value(https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=384456
Additionally, there is a way (hack) to access the internal collection of headers to bypass the validation: http://blog.scoftware.com/post/2009/07/28/SOLUTION-HttpWebRequest-raw-headers.aspx 

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
//Create a HttpWebRequest to Front End A's IP Address 
HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://10.0.0.1");
//Modify Host header to reach intranet.fabrikam.com 
myHttpWebRequest.Headers[HttpRequestHeader.Host] = "intranet.fabrikam.com";
//Process Response HttpWebResponse 
myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream streamResponse = myHttpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(streamResponse);
string strHttpResponse = streamReader.ReadToEnd();
//Output Response 
Console.WriteLine(strHttpResponse);
streamResponse.Close();
streamReader.Close();
myHttpWebResponse.Close();

Third Method (Using WebClient or WebRequest (method B)): 
Using the Proxy property of WebClient you can target http://intranet.fabrikam.com and connect to 10.0.0.1
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
//Create a WebClient 
WebClient webClient = new WebClient();
//You can eventulay set a Username / Password as NetworkCredentials 
webClient.Credentials = new NetworkCredential("username", "password");
//The Front End A's IP Address to connect to 
webClient.Proxy = new WebProxy("10.0.0.1");
//Will set the correct Host Header 
Stream streamResponse = webClient.OpenRead("http://intranet.fabrikam.com");
//Process the HttpResponse 
StreamReader streamReader = new StreamReader(streamResponse);
string strHttpResponse = streamReader.ReadToEnd();
//Output the HttpResponse 
Console.WriteLine(strHttpResponse);
streamResponse.Close(); webClient.Dispose();
That’s all for today !

Sunday 30 August 2009

Silverlight 3 in SharePoint 2007 with Document Preview (Part 0)

Here is the first part of my guide to add Document Preview in SharePoint 2007 and Silverlight 3 to preview them.

To achieve this, I’ll be using these technologies/components (more will come):

  • Silverlight 3.0
  • SharePoint 2007 (either WSS 3.0 or MOSS)
  • Microsoft SharePoint SilverView (available on CodePlex)
  • Windows Communication Foundation

The big picture (subject to updates along the posts):

image

So, We’ll take a standard SharePoint architecture and extends it to generate Document Preview and allow Silverlight to upload files to a document library.

Things we’ll do:

  • Add some WCF in SharePoint
  • Extend the Microsoft SharePoint Silverview sample to get thumbnails of Documents in SharePoint
  • Create Document Preview of (at least) Microsoft Office Documents

 

What are new in that big pictures ?

  • Thumbnails Service WCF
    • Allow Document Preview generation
  • Upload Helper WCF
    • Enable Silverlight application to upload file to a document library (we’ll review why i choose this way)
  • The extended Microsoft SharePoint Silverview

 

In the next post, I’ll briefly introduce Microsoft SharePoint Silverview and extend it to handle more than Image preview.