Category Archives: ASP.NET

ASP.NET Adventure. My new project using SignalR.

image

I’m currently working on a set of applications to handle the main tasks of my family’s restaurant. This is a snapshot of the client for the kitchen. It’s on a very early state, but you can mark product orders as “Done”. It uses Entity Framework and some concepts of Domain-Driven Design. It’s also using Windows 8.1 and Windows Phone 8 for the clients (the waiters will have another kind of client to request orders to the kitchen.

SignalR is needed to notify waiters when an order is ready (or even when a product is ready). I wanted to share the progress on this! Smile For the moment, I think Windows 8 is a bit limiting in terms of layout. WPF is far more complete. But it doesn’t feel bad at all. I think the lack of Triggers for Styles will be a big headache, but some people are working on a MVVM-friendly way to face this using Visual States.

I also feel the asynchrony will be a major let down in a later stage of the solution, but with a bit of help, it can be done. I want to start it simple!

I hope you like it. The background is a bit lame, but I like blue hues! haha Open-mouthed smile

Hey, my picture appears in each order, but a picture of each waiter will appear in a few iterations, of course Smile with tongue out

ASP.NET adventure SignalR (Part 2)

Now that I have a running application that is, actually, a website based on MVC, I feel something strange. I wanted something like a classic web service, but instead, I got a bunch of pages, controllers and some generic classes to setup SignalR Confused smile

Is that necessary? I think I’m taking my eye off my goal! I didn’t even want a website.

Hopefully somebody will help me. What would I do without Internet and my friends on Twitter, LinkedIn, Skype… ??

Just to keep myself on track:

From the beginning I tried to make a “hello world”-like application. Something to get me into the business. To be more specific, I thought of an (very simple, of course) application that consist of about a server a clients (pretty common!)

  • The server accepts a number of clients.
  • After a client is connected, the server keeps sending a text message every t seconds. For example, every 5 seconds, it sends a message “Hi, client n”.
  • When the client receives the message, it should just show it on the screen.

To make it even better, I thought of making a Windows Phone 8 client.

What should I do, starting from the latest post on the matter, in order to get both server an client?

ASP.NET adventure! SignalR

As I’m an adventurer and I don’t want to get an arrow in the knee, I’ve put my wellington boots and dug a bit into the topic about distributed services, surrounding the web, brrrrhh!! Confused smile 

My friend Xavi (@XaviPaper) told me about SignalR when I mentioned an application that I want to make as a way to practice. In the meanwhile, to get sure that I’m not wasting time learning how to start my first SignalR application/s using old methods, I downloaded Visual Studio .NET 2013 RC (Release Candidate) to get the latest bits. I’m always with the new and tasty Smile But that usually means I problems.

After touching here and there I haven’t had any luck. So I asked Xavi who told me to go to “Variable not found” a blog run by José María Aguilar (@jmaguilar) who seems to be a master on this topic. I contacted him directly, and he kindly tried to guide me. I told them I would try to walk through all the process and come with the results. So I decided to do it and RECORD the process.

Yes, I armed myself and face the problem! knowing that some of the best colleagues are there to help me out. Jumping with a net is really better Smile

The first problem I encountered is that I cannot even have a working base application to start. The most basic skeleton for some simple app. Maybe it’s because I’m just too new to ASP.NET/MVC or whatever technologies are used for this (believe me, there are a lot of them implied into the most basic template!)

To illustrate my short journey into this new world I captured every step I did. Everyone is labeled with a number for anyone to refer to a particular step in order to correct me (because I think I’m doing it wrong in some place).

Step 1.

Visual Studio 2013 RC itself!

image

Step 2.

File > New Project…

image

Step 3.

I choose Visual C# / Web / ASP.NET Web Application and give it a name.

image

Step 4.

After clicking “OK”, a new dialog pops up. I choose MVC blindly. I don’t really know the reason to do it, but I’ve seen this in some tutorials Smile with tongue out I would like to make a web service that sits silently and serves a range of clients (Windows Phone 8 / Windows 8, for instance).

image

After that, I press “Create Project”

Step 5.

An entire structure is created. Wow. That is huge!

image

Step 6.

To add SignalR to the project I deduced I had to install the NuGet package. I choose to manage packages in the project.

image

Step 7.

I explicitly choose “Include prerrelease” in the combo and choose Microsoft ASP.NET SignalR. I press the “Install” button.

image

After that, a lot of packages (some even include JavaScript/jQuery, my dirty nemesis!)

Step 8.

A readme.txt file appears, giving some info about how to setup SignalR.

image

The document states:

“To enable SignalR in your application, create a class called Startup with the following”

Step 9.

It shows a sample class called “Startup” and it says that you have to create it, but oh boy! I discovered, horrified, that it already exists!!

image

Step 10.

It’s there! Startup.cs. Let’s check it.

image

Step 11.

Not only it already exist, but it’s different from the one that the readme.txt shows.

image

And now, what?

EDIT:

Step 12.

Following Jose María’s directions, I replace the code in the Startup class with the one the readme.txt file.

So the class remains:

using Microsoft.Owin; using Owin; [assembly: OwinStartupAttribute(typeof(ChorriApplication.Startup))] namespace ChorriApplication { public partial class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } } 

 

Step 13.

After the change, I decide it’s time to run the application and I press F5 and this is what it’s shown!

image

Pretty good, uh? Open-mouthed smile It shows something, at least.

I close the browser window (Internet Explorer powah! Winking smile)

Step 14.

I’m trying to add a Hub class, since I have heard that hubs are like services that concurrently listen/send messages from clients.

I’m doing it via context menu, clicking over the project in the Solution Explorer.

image

A small dialog appears and I type my hub’s name.

image

Step 15.

Click on OK and a new class is created.

image

So, my Hub says hello? Well, and what can I do with that?

I think I’m done for today! I have no “clients” and NO IDEA of how to continue. I hope some colleague points out some new steps for me to follow.

But something is sure: whichever it is my way, I will show you Smile