Blogger Widgets
  • Sharing Photos using SignalR
  • TFS Extenstion - allows copy work items between projects
  • Displaying jquery progressbar with ajax call on a modal dialog
  • Managing windows services of a server via a website
  • Exploring technologies available to date. TechCipher is one place that any professional would like to visit, either to get an overview or to have better understanding.

Search This Blog

Friday 16 December 2011

Capturing network traffic between outlook client and exchange server (RPC over HTTP)

My previous article show how to capture network traffic between outlook client and exchange server with RPC over TCP. Now lets look at how to capture network traffic with RPC over HTTP.

1. Enable "Outlook Anywhere" on your Exchange server. Follow this link Enable Outlook Anywhere.

2. Now enable your outlook to use HTTP. Follow this link Setting Up Email (RPC over HTTPS).

Since all prep has now completed just follow the steps in my previous article Capturing network traffic between outlook client and exchange server (RPC over TCP).

I am sorry to say that there is too much point to the wisecrack that life is extinct on other planets because their scientists were more advanced than ours. ~John F. Kennedy

Capturing network traffic between outlook client and exchange server (RPC over TCP)

Analysing network traffic between outlook client and exchange server will help you decide network requirements connecting your datacenters to your users (ie.. using RPC over TCP). Wireshark is a simple tool that we are going to use to capture network traffic [ Download Wireshark ].

Information you should know before hand:

- IP address of client using Outlook (eg: 1.2.3.4)
- IP address of your exchange server (eg: 1.2.3.5)
- Outlook able to connect to your exchange server

Now here is the step-by-step guide.

1. Open wireshark

2. click on the interface (see screenshot above). Now you should see wireshark capturing network traffic. sample screenshot can be viewed here

3. Now start outlook

4. perform you routine tasks with outlook and let wireshark capture do the capture (leave this running for 30 mins)
5. Now stop capturing using the button


6. Save your capture


7. Now specify your filter "ip.src == 1.2.3.4 and ip.dst == 1.2.3.5" (use your exchange server IP address), this should display network traffic netween outlook client and exchange server. Filtered data gets displayed

8. Now select Statistics -> Summary. "Wireshark: Summary" dialog displays some very useful traffic information such as :-

- Between first and last packet (time taken in secs)
- Avg. packets/secs (average packets per sec)
- Avg. packets size (average packet size)
- Bytes (total amount of bytes transfered)
- Avg. bytes/sec (average bytes per sec)

Note that "Displayed" column is what you are interested as it shows data based on your filter. "Captured" columns will show everything.


. Any sufficiently advanced technology is indistinguishable from magic. ~Arthur C. Clarke

Tuesday 13 December 2011

Using images in Microsoft’s Sharepoint Wiki

Today I was creating a wiki page for a project and want to show the design inside the wiki page. Ok that was not too difficult as wiki page editor provides an option to select an image. So I have tried using the link to image as "file://C:/Users/saif/Desktop/elapsedtime.png" but that did not work.
So I have created a picture library as per following steps :-

1. goto http://saif-teamserver/sites/DefaultCollection/default.aspx

2. goto "Site Actions" and select "Create"

3. select "Picture Library" as shown below


4. Give a name "SaifProjectPics" and select "create" should show your library


5. Now upload the image "elapsedtime.png"


6. clicking on the image should show the image in edit more, click on the image again so as to display as preview. The url should look like http://saif-teamserver/sites/DefaultCollection/SaifProjectPics/elapsedtime.jpg


That's it you can use this url in your wiki page. Try to add image in the wiki page and use the url as "http://saif-teamserver/sites/DefaultCollection/SaifProjectPics/elapsedtime.jpg" and your wiki page will have the image you needed.

The system of nature, of which man is a part, tends to be self-balancing, self-adjusting, self-cleansing. Not so with technology. ~E.F. Schumacher, Small is Beautiful, 1973

Wednesday 7 December 2011

ASP.NET MVC using fileresult to export data in unicode

Exporting data to a file is a common feature websites provides to its customers. Now consider if the website is used by customers around the world, then this export data should support localization and globalization. Here is the snippet of code relating to WriteFile() for exporting data:-
protected override void WriteFile(HttpResponseBase response)
{
            response.Clear();
            response.ClearContent();
            response.ContentEncoding = System.Text.Encoding.Unicode;
            StreamWriter writer = new StreamWriter(response.OutputStream, Encoding.Default);
            writer.WriteLine("Test Data");
            writer.Flush();
}
Since "response.ContentEncoding = System.Text.Encoding.Unicode;" is assigned to correct encoding browse should enforce writing data in unicode format but point to remember is streamwriter is initialised with encoding as "Encoding.Default". So browse ignores content encoding. Modify your code to have
StreamWriter writer = new StreamWriter(response.OutputStream, Encoding.Unicode);
Now this will enforce unicode format of the file. Also to verify if the file format is correct, rename the file to .bin and open Visual Studio to see the file in hex format. Verify the Byte Order Mark (BOM) of the file. First four char's "FF FE" confirms the file to be in unicode format. Refer to this article UTF-8, UTF-16, UTF-32 & BOM for more details about BOM.

Never trust anything that can think for itself if you can't see where it keeps its brain. ~J.K. Rowling

ASP.NET MVC not rendering correct dateformat using CultureInfo

Reading "DateTimeFormat" using cultureinfo is not getting clients date format with the following code :-
CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(HttpContext.Current.Request.UserLanguages[0]);
DateTimeFormatInfo dtInfo = cultureInfo.DateTimeFormat;
After debugging the code, the dateformat is not honouring globalization ie.. if the client is in US but application is deployed in UK then the format is rendered correctly. So after looking into this article Globalization, Internationalization and Localization in ASP.NET MVC 3, JavaScript and jQuery Part 1 - by Scott HanselmanI have found that the issue is not with the code but a setting in web.config
globalization enableclientbasedculture="true" uiculture="auto" culture="auto"
Now this has solved the issue.

I am sorry to say that there is too much point to the wisecrack that life is extinct on other planets because their scientists were more advanced than ours. ~John F. Kennedy

Tuesday 6 December 2011

Using session locking with EnableSession = true

Locking session object for each webservice is simple as just adding [WebMethod(EnableSession = true)] for each of the webmethods that require locking. At the same time if you also want to lock an object that is/will be part of the session object then Declare a static object
public static object lock_updatesharevalue = new object();
Now use this object in the webmethod to enable locking for an object in session
[WebMethod(EnableSession = true)]
public int UpdateShareValue(string Shareidentifier,float Sharevalue)
{
 lock(lock_updatesharevalue)
 {
    ///Update database with new share value
 }
 Session[Shareidentifier + "CurrentShareValue"] = Sharevalue;
}
So firstly session object is locked and then you are forcing a lock on a static object inside the webmethod that solves the issue of value failing to update when there are thousands of requests comming. Also point to note at this point is this method makes all the calls serialized and hence might reduce the performance and some of the calls might be waiting longer than expected so remember to increase the timeout in web.config
httpRuntime executionTimeout="10000" maxRequestLength="102400"
Refer to this article about Session State Overview

The real danger is not that computers will begin to think like men, but that men will begin to think like computers. ~Sydney J. Harris

Monday 5 December 2011

NHibernate : Arithmetic overflow error converting expression to data type int

As mentioned in SQL Server Error : Arithmetic overflow error converting expression to data type int article to use cast() in sql to correctly typecast for large numbers, Now this can be achieved using NHibernate & Fluent Hibernate as per the snippet below:-

 var criteria = session.CreateCriteria();
 criteria.SetProjection(Projections.ProjectionList()
 .Add(Projections.Count("ID").As("ID"))
 .Add(Projections.Sum(Projections.Cast(NHibernateUtil.Int64, Projections.Property("imagesize "))).As("TotalSize")))      
.SetResultTransformer(NHibernate.Transform.Transformers.AliasToBean(typeof(ImagesSummary)));
ImagesSummary summary = (ImagesSummary)criteria.UniqueResult();

I regularly read Internet user groups filled with messages from people trying to solve software incompatibility problems that, in terms of complexity, make the U.S. Tax Code look like Dr. Seuss. ~Dave Barry

Friday 2 December 2011

SQL Server Error : Arithmetic overflow error converting expression to data type int

After running a simple aggregate sql "select sum(imagesize) from images" is producing following error:-
Arithmetic overflow error converting expression to data type int
The table "images" is a very simple, having datatype of imagesize as bigint. The table has at least 2 million rows and should not be a problem at all. Tried number of options but no luck and finally found out the issue is actually because of the aggregate function it self. Aggregate function "sum" returns int but the totals of imagesize field is exceeding the size of int and hence was showing the error message. So the fix for this is changing the sql to return bigint as follows :-
select sum(cast(imagesize as bigint)) as 'TotalImageSize' from images
Now this worked.
Your most unhappy customers are your greatest source of learning. – Bill Gates
Copyright © 2013 Template Doctor . Designed by Malith Madushanka - Cool Blogger Tutorials | Code by CBT | Images by by HQ Wallpapers