Saturday, July 28, 2012

Software coding jargon

An interesting list of new coding jargon: (or check out this page for the original content:

(The page is originally from StackOverflow, but that question was deleted and hence the link to stack-printer).

One of my favorites:
"Yoda Conditions"— using if(constant == variable) instead of if(variable == constant), like if(4 == foo). Because it's like saying "if blue is the sky" or "if tall is the man".

A history of software failures....

Came across this interesting graphic from an old IEEE article:

And while you are still interested in the topic, read the following:
Some stories on failures of software:
History's worst software bugs:
And if you are looking for some latest stories, then the "Risks Digest" is a great place to get them:

Thursday, July 26, 2012

Using WCF with windows authentication with an intranet ASP.Net website

You want to use windows authentication to protect a WCF service and the client is an ASP.Net intranet website (and has Windows Authentication turned on).

Create your WCF webservice website (I am assuming that the web-service website is different from the intranet website).

Enable Windows Authentication for the site.


For the purposes of testing create a service method that returns the user info:

public string GetUserInfo()         
             string userinfo = string.Empty;
             var windowsIdentity = ServiceSecurityContext.Current.WindowsIdentity;
             if (windowsIdentity != null)
                 userinfo = windowsIdentity.Name;
             return userinfo;        

Setup the web.config for the service so that the end point uses basicHttpBinding with a configuration where the security mode is set to “TransportCredentialOnly” and the Transport’s clientCredentialType is set to windows. Here is what it will look like:

       <service name="WcfService1.Service1">
         <endpoint address="Service1.svc" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration" contract="WcfService1.IService1" />
         <binding name="basicHttpBindingConfiguration">
           <security mode="TransportCredentialOnly">
             <transport clientCredentialType="Windows" />
           <serviceMetadata httpGetEnabled="true"/>
           <serviceDebug includeExceptionDetailInFaults="true"/>
     <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />   </system.serviceModel>

Create your ASP.Net website (which will act as a client to your web-service). Set its authentication mode to “Windows” and make sure that you set "identity impersonate” to true.


Now add a reference to your web-service.

In your web.config make sure that the security mode is set to “TransportCredentialOnly” and the Transport’s clientCredentialType is set to windows. Here is an example:

         <binding name="BasicHttpBinding_IService1">
           <security mode="TransportCredentialOnly">
             <transport clientCredentialType="Windows"/>
       <endpoint address="http://xxxxxx/Service1.svc/Service1.svc"         binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"         contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />

That should be it. When you call “GetUserInfo”, you should get the name of the user that is accessing the asp.Net website.

Saturday, July 21, 2012

CRM 2011–error when upgrading a CRM 4 database

I recently got an error that stated “could not load file or assembly 'Microsoft.Crm.Sdk, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.” while I was importing a CRM 4 database into a CRM 2011 instance.

The way I managed to get around it was to add the following section right at the end of the CRMWeb’s web.config file (right before the ending configuration tag)

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <assemblyIdentity name="Microsoft.Crm.Sdk" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion="" />

Location of VPN settings in Windows 7 and Windows 8

I needed to copy the VPN settings from my Windows 7 machine to my test Windows 8 machine and wanted to figure out where the settings are stored. Here is the location:


In that folder you will find a file called “rasphone.pbk”. You can copy that file out and double clicking it, will open the “Network Connections” dialog and you will find all your VPN connections in that dialog!

Setting up Foscam FI8190W for remote access

Here is how you can setup your Foscam FI8190W for remote access (and this will work for almost all web-cams).

I am using a router which has the DD-WRT firmware installed on it. If you don’t have DD-WRT, your router setup will look different, but you should find pages on how to perform it for your specific router.

Step 1: Connect to your web-cam and perform setup

Install the software that came in the Foscam box. Run the “IP Camera tool” to figure out the IP address for the camera.

Connect to the IP camera using the IP address provided by the “IP Camera tool”. (The address will typically be of the form, where xxx is a 3 digit number that will be unique for you. This address is the internal IP address for your web-cam (as opposed to WAN IP address which we will learn about later)).

You will see the login screen:


The first time you connect to your web-cam, the user name is “admin” and password is blank (no password).

After logging into the web-cam, we need to do some house keeping steps:

1. Change the password. When changing the password, what you need to know is that the password is case-sensitive and can be only 12 characters long.

2. Change the port used by the web-cam:

The main reason we are changing the port is because the default port of 80 is blocked by many ISPs and so by changing it to a different value like 82, you get around that issue.


Note: once you change the port you will connect to the web-cam using the port number using the following format (, where xxx is a number unique to your web-cam setup and pp is the number you entered for the Http Port)

2. Setup your router

Login to your router. As I am using DD-WRT, the url for me is:

Setup port forwarding:


Click on “NAT/QoS”

Click on Port-Forwarding

Set the application name.

Set the “port from” to the same port number that you set in Step 1 above. Set the “IP address” to the IP address of your web-camera. Finally set the “Port to” value to the same port number that you used in “Port From”.

Click on “Save” and “Apply Changes”.

Now in the screen shot above, lookup the “WAN IP:” value (top left corner, red rectangle).

This is the IP address that you need to use to connect to your web-cam from outside your home’s network.

3. Make sure that all your settings are correct to enable remote connectivity:

From your home network, open a web-browser and browse to:

The web-page should automatically detect your external IP address. This should correspond to your “WAN IP” address that you found in step 2.

Set the port value to the same value you chose in step 1.


Click on “Check your port”

If you see the following message, then your setup was unsuccessful and as a first step, I would go through all the above steps a 2nd time to make sure you didn’t miss anything:


But instead, if you see this message, then everything is good and you can go on to the next step:


4. Connect up to your web-cam

You should be able to connect to your web-cam using the external IP address (WAN IP) and the port number like so: (where is an example for what my WAN IP address and 92 is the port number I selected for step 1).

5. Setup Dynamic DNS (DDNS)

If you don’t have a static IP address (what that means is that your WAN IP address gets reset to a different address every few days), then keeping track of your external (WAN) IP address can become a real pain. Enter DDNS.

I used the free website to setup my account.

After you create your free account, click on Hosts/Redirects:


Click on “Add a host” and setup your host like so:


(The IP Address should be set to your WAN IP address).

Click on “Create Host”

Wait for about 5 minutes for the new host name setup to be completed by

Open a browser and navigate to (where justAnExample and no-ip were values I selected above and 92 is the port number I chose in step 1).

You should be connected to your web-cam now.

Setup router to update your DDNS record automatically.

Again, I am using DD-WRT as my router, but your router (if different) should support a similar setup).


Click on “Setup” –> “DDNS”

Select “NO-IP.Com” as your service.

Enter the user name and password that you selected when you created your account.

Finally enter the host name you selected above (in my example that was:

Click on Save and Apply Settings.

That’s it you are done!

And here is a screen shot of my web-cam as seen on my iPad:



If you get an ActiveX error in Internet Explorer, check out these steps on FOSCAMs site for fixing it:

Wednesday, July 11, 2012

Sql Server–Convert UTC time to Local Time

Here is a quick function that you can plug into your sql query to convert a field that has UTC time to local time:

dateadd(hour, DATEDIFF (HH, GETUTCDATE(), GETDATE()), Timestamp) as ltime

Where Timestamp should be replaced by the field in your table that contains date-time in UTC.

Saturday, July 07, 2012

Rotating videos (specifically MP4)

I had taken a bunch of videos using my Nokia 800 and they were all great. Unfortunately, once I downloaded them to my computer, I realized I took them all while holding the phone upside down! And in my quest for free software that could rotate a MP4 video file, I downloaded quite a few tools and most of them turned up short and were filled with crap load of crapware!

Finally I came across “Freemake Video Convertor”. Now, even this software came with a bunch of software that it wanted to install on my computer. But they at least give you an option to opt out. Also, you can donate to their company if you end up using their software and like it.

You can download Freemake Video Convertor from:

Some other nice features of this software:

Convert videos from a variety of formats to a variety of formats (output: Avi, MP4, Wmv, Dvd, etc).

Also, the software makes it easy to replicate the quality settings of the input file.

You can also crop the video.