I was trying to call the OData service in CRM. I was using the good old jQuery $.getJSON function. It was failing with the “errorThrown” parameter telling me “No Transport”.
I had a vague recollection of hitting this error in a different context last year, so I looked it up and found that the error can be caused by a cross-domain Ajax request.
On the surface, this didn’t really explain my problem. My browser was pointing at my CRM installation and I was making a call to the OData service on the same installation. So why the cross domain issue?
I hunted a bit more and here is what I found: I was using the Xrm.Page.context.getServerUrl function to make sure I had the right server url BUT this function does not return the domain the browser is using. Instead it returns the domain that was set in the config of the CRM installation.
So if you navigated to the CRM installation using the domain name “crm” and the config says “crmserver03”, then calling getServerUrl will return a different domain to the one your browser is using. In this case, if you use getServerUrl to build the URL for an Ajax call then you will be using a different domain name and will get the “No Transport” error (unless you’ve done this: How to make a cross-domain Ajax call in jQuery).
I think that’s a bug in gerServerUrl.
Anyway. Here is my fix:
var url = window.location.protocol + "//" + window.location.host + "/" + Xrm.Page.context.getOrgUniqueName();
Or, for a relative url, you can use:
var url = "/" + Xrm.Page.context.getOrgUniqueName();
Whichever suits your needs.
Update: See comment below from Carsten Groth and my reply for a new Xrm function that returns the correct url.
I’m currently trying out the ASP.NET MVC 4 Beta and I thought I’d give the Single Page Application tutorial a shot.
I’ve created several single page apps so far and they’re working well and people are using them successfully, but now that I’ve had some experience I look at them and wish I could rewrite them from scratch. If you look back at code you wrote six months ago and don’t think that you could do it better now then either you are perfect or you have stopped learning and are fast becoming antiquated.
So I followed the instructions, hit F5 to run the web site, typed “Tasks” in the address bar and … aaargh! An exceptions in the view and a really unhelpful error message. “System.InvalidOperationException was unhandled by user code” and “Failed to get the MetadataWorkspace for the DbContext type ‘MvcSpaApp1.Models.MvcSpaApp1Context’.” The inner exception was no better: “System.Data.ProviderIncompatibleException” and “The provider did not return a ProviderManifestToken string.”
Luckily I’ve been reading up on Entity Framework Code First, so I knew what the problem was – I didn’t have SQL Server Express running. So I started up SQL Server Express and … still didn’t work. But this time it was because I didn’t have rights to SQL Server because I was using a machine someone else set up and they had mucked up the security. Anyway, when I finally got it all sorted out the site ran without any problems.
So just be aware: YOU MUST HAVE SQL SERVER EXPRESS RUNNING and YOU MUST HAVE DATABASE AND TABLE CREATION RIGHTS.
Other than those gotchas the tutorial is good.
A while ago I tried and tried and tried and tore out my hair trying to install npm on Windows (in case you’re new to node-js, npm is the Node Package Manager – sort of a NuGet for Node).
I followed the instructions but I got all sorts of annoying errors that I just could not get around no matter what I tried. So I gave up.
A couple of days ago I saw that there was a nice looking book called “Node for Front-End Developers” that looked like it didn’t need any packages installed, so I bought it and decided to get the latest version of Node. I went to the Node website and there on the home page was a download button that popped up a choice of Node versions for Windows, Mac or any other platform (by getting the source and building it yourself).
I ran the Windows installer and (hoo-friggin-ray!) it installed npm at the same time.
The new installer is nice and simple – it just runs and installs Node. What more can you ask for in an installer? (Well, maybe giving the choice of where to install Node would be good, in case you don’t want to put it in “c:\program files”.)
One gotcha about running npm in Windows 7 – if you are installing something globally, you must run npm as an administrator because it is under “c:\program files” and any changes you want to make in that area require admin privileges.
Anyway, I got started on the book, which is very hands-on, and I’m learning more and more about Node.
I’ve recently come across some good intro podcasts on node.js.
I’ve been listening to the .NET Rocks podcast for a while now and their latest show is a talk with Tomasz Janczuk, the guy at Microsoft who is working on porting node.js to Windows and IIS. It’s a good intro for all types of developers but is probably aimed at .NET devs more than open source or Java devs.
» .NET Rocks – Show 711: Tomasz Janczuk Builds Web Apps with node.js – As well as the basics on what node.js is and how you use it, there is some very good data on when you’d use iisnode versus basic node.exe.
I only came across the Herding Code podcast a few weeks ago, but I like it so much that I’ve already caught up on all the shows for this year and a couple of the earlier ones that covered topics I’m interested in. The four presenters are real pro devs and the discussions are always really lively, funny and interesting.
There are two node.js related shows:
» Herding Code 102: Tim Caswell on Node.js – this is an excellent intro that goes beyond the basics and explains the event loop of node and the non-blocking async programming model it uses. This gives you a good foundation.
» Herding Code 122: Bert Belder on porting Node.js to Windows – This is about more than just porting node to Windows, which is very interesting in itself, it builds on show 102, so listen to that one first.
I hope these are helpful.
The instructions I used are at WebMatrix and node.js: The easiest way to get started with node on Windows
Here’s how it went for me:
- WebMatrix Install: It took a looooong time to install, about 30 minutes. I was running quite a few things on my machine at the time, including VS2010 and SQL Mgmt Studio, but it still seemed like a heckuva long time, so be patient.
- iisnode for iis7 express (x86) Install: If you don’t have Microsoft Visual C++ 2010 Redistributable Package (x86) installed then the iisnode installer will tell you that you need it. Just click my link here and get it. It installs easily and then the iisnode install is a piece of cake. (FYI: You’ll have the same “This program is not commonly … etc.” message if you try to run after downloading in IE9 and that’ll happen on the next two also.)
- iisnode for iis7 (x86) Install: For my messing about I didn’t really need to install it but I wanted to anyway. There were no issues.
- iisnode for iis7 (x64) Install: I didn’t install this, ’cause I’m using a 32 bit machine for this messing about, but if you are installing the x64 version then I’m guessing you’ll need the C++ 2010 redistributable for x64.
- node.js templates for WebMatrix: Easy install. Thanks to Steve Sanderson (the genius behind knockout.js) for the templates
If I get some time free and I feel courageous, I might try to figure out how to use VS2010 to write node apps. If anyone out there has already done it then please leave a comment – no point in re-inventing the wheel.
I installed node.js a month or so ago and it wasn’t too much trouble, but I had to install Cygwin and other stuff with it for it to work on Windows. I wasn’t interested in taking the time to compile it myself, so I used what the node.js guys were good enough to supply.
I wasn’t looking forward to upgrading though, but Tomasz Janczuk came to my rescue! He’s been working on making node.js work on not just Windows but also in IIS AND IIS Express. All the links you need to download node.js are here: Current installation packages for node.js and iisnode for Windows.
Instructions on how to get started using it are here:
- Getting started with node.js on Windows
- WebMatrix and node.js: The easiest way to get started with node on Windows
- Node.js community wiki