Saving a jQuery event handler for later use

Quick note: If you need to save an event handler so you can unbind the event and rebind it later, the code below will do the trick. This is especially helpful if you’re using a jQuery plugin that attaches events to your element, but you want to temporarily unbind it.

var submit = $("#submit");
//Save original click event handler for later
var click ="events")["click"][0].handler;
//Unbind click event
//Bind click to original event (e) {
	$.proxy(click, submit)(e);

An easy way to create a self signed certificate

I needed to create a self signed cert to test my WCF service with username authentication in my dev environment (if you need help with this, I recommend Tried using Windows makecert cmd utility but it was give me problems. So I found a nifty tool from pluralsite called self-cert ( It has a simple intuitive UI and works like a charm. But don’t forget to run it as an administrator.

WCF basicHttpBinding – 504 Gateway Timeout

I had a WCF service secured with SSL, using wsHttpBinding, Message security mode, and UserName authentication. Everything worked find because I created the client app in VisualStudio and it automatically generated the appropriate tags in web.config. I was able to connection, authenticate and call methods without issue.

But now I need to adjust the service to allow clients of other technologies to connect to it…more specifically PHP. PHP can’t connect to a service that uses wsHttpBinding. It has to be basicHttpBinding because it conforms to a broader standard.

The first thing to do is change system.serviceModel/services/service binding attribute to “basicHttpBinding”. Then create a <basicHttpBinding> node under system.serviceModel/bindings. Because we can’t use the Message security mode with basicHttpBinding, it needs to be changed to TransportWithMessageCredential. And that’s basically it for the service.

Now just publish it, connect to it from your client and call it a day. Well it didn’t go that smoothly for me. My client app I create for the original wsHttpBinding service was griping with an error: The remote server returned an error: (504) Gateway Timeout. Update the service reference? Nope that didn’t help. Remove and create the service reference? Nope, same error. So then I tried playing with the service configuration to no avail.

Finally I decided to read the stack trace and saw “There was no endpoint listening at https://myremoteservername/service.svc that could accept the message. This is often caused by an incorrect address or SOAP action.” Weird, how did it know the name of my server? I went back to my client’s web.config and looked at the endpoint VS created with I added the service reference. Indeed the address contained the server name! I changed it to the publicly accessible domain name and it works.

For some reason, when VS references a service with basicHttpBinding, it uses the server name. But I have no idea how it got the name in the first place. When adding the reference, I entered the public (correct) .svc url.

I’ll have to check with our network guy about it but I’m happy it’s finally working.

Installing SSL on IIS7 with host headers

I have one wildcard SSL certificate and needed to use it on multiple subdomains. The IIS7 UI doesn’t allow you to specify the host header when configuring an ssl binding. The only way I found to do it was by using appcmd from the command prompt. The command works as such:

appcmd set site /"<IISSiteName>" /+bindings.[protocol='https',bindingInformation='*:443:<hostHeaderValue>']

<IISSiteName> is the name of your site in IIS. <hostHeaderValue> is the host header you’re trying to bind to.

I found this tidbit on According to their steps, you should install the ssl on one site with the admin console first before using appcmd. I’m not sure if this is true. I assume you can use appcmd for all of them.

SQL Named Instance Port Number

Heads up, you probably know the default port for SQL is 1433 but did you know the port is different for a named instance? And this port is dynamically set when you install the server. You can see what it is by looking in the registry. The below registry path is for SQL2008.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.(InstanceName)\MSSQLServer\SuperSocketNetLib\TCP\IPAll

There are more details in this article

And if you are using a named instance SQL server, don’t forget to adjust your connection string.

<add name=”MyConnString” connectionString=”Data Source=MyServerName, 51601; Initial Catalog=Northwind;user id=MyUserName;password=SecretPassword” providerName=”System.Data.SqlClient” />

Notice 51601 is the port number.

Using a movieclip you created in Flash, in Flex

If you want to create a nifty movieclip in Flash but want to use it in your Flex application, you will need to export it as a .swc then import it into Flex. The first step is to right click on the movieclip in your Flash library and select Component Definition. The main thing to enter in the pop up window is the Class name. This will be the name of the class you instantiate in Flex. After you click OK and the window closes, right click on the movieclip in the library again and select Export SWC file. Once that’s done, you’ll need to add the .swc to your Flex library. In Flex, under the Project menu, select Properties. Go to the Flex Build Path section. Click on the Library Path tab. Click the Add SWC button and navigate to the file you just created.

That would seem to be all but it’s not. If you try create an instance of the class as you would any other class in Flex, you’d get an error. For example:

var x:myClass = new myClass();

will give you this error: Type Coercion failed: cannot convert myClass@6f3c9c1 to mx.core.IUIComponent.

The trick is to wrap your class with a UIComponent. So your code should look like this:

var x:myClass = new myClass();
var wrapper:UIComponent = new UIComponent();

That’s all there is to it.

Here’s an example of using the FLVPlayback component in Flex