Wednesday, June 17, 2015

Learning JavaScript the hard way: 1 - dont minify in beta

Being a seasoned vet with C# i find the world of javascript rather sensible, although there are a few pitfalls. One difference is the use of minified files. Since javascript is parsed, rather than compiled there is a great push to make the source as small as possible, thus allowing for faster loading sites.

One way of achieving this would be to write javascript the same way C++ devs write their code; with truncated and unreadable variable names, and without any comments except the ever so loved "\\change this".

The good news is that javascript devs are not C++ autists, and the prefered solution is a fair bit more sane.

The common practice is called minifying. And it consists of parsing the source files thru a program that changes out every var with a short-as-possible name, and removes all unneded whitespace and comments. This makes the code unreadable for sane humans, but saves space.

 Below is an example of code minified using http://jscompress.com/

This is a normal un-minified javascript function (388 bytes)
This is the same function minified (188 bytes)
But back to the problems: Being new to javascript i just downloaded the minified versions of all my libs (angularJS, jQuery etc.) and this lead to problems during debugging, as all the error messages were less than readable.

Switching out the minified files with the large uncompressed ones made things alot easier.

Friday, June 12, 2015

WCF on IIS: configure permissions

I modified my WCF service to get/set data from a SQL database, in order to make it a usefull service. And after adding the functions i needed i debugged it and everything looked fine. But then upon uploading it to my IIS server i was unable to get access.

The problem was inadequate permissions, and so i started down a long road of error checking.

First off all i checked these two off my list:

  • Newcomer advice 1: Install WCF support for IIS
  • Newcomer advice 2: Add the service as an application in IIS Manager


Having done those the first step i had to do was changing the permissions to use the ApplicationPool:
After doing this i was allowed to view my site, or at least the non descriptive error messages it gave me.


The second step i did was change my web.config a little, so i could get descriptive error messages:

Now I could see there was something wrong with my SQL permissions, as IIS APPPOOL\ASP.NET v4.5 was denied access. So next step was to open SQL Management Studio and add this name as a user:


After adding the user, and setting my table 'arbeidslog' as the default for the user i added the permission 'db_owner' on the User Mapping dialog. (Security -> Logins -> IIS APPPOOL\ASP.NET v4.5)

And that was it, Service is now spitting JSON from my database just like it's supposed to.

Wednesday, June 10, 2015

An example of a WCF web service that returns JSON


Currently developing a project in javascript, and at some point or another that means getting recieving some data from the server. Doing this properly, and for cross platform support means writing a service that can push JSON data.

VisualStudio has a nice template setup for WCF and ASMX services, but they push XML by default.
Some modification is needed for JSON, and also some web.config changes should be made to allow for cross domain interaction.

A sample project is uploaded here (zipped):
https://drive.google.com/file/d/0B6AihF9gdNcnWHEzZkZtNWVpUXM/view?usp=sharing