Sorted By: Tag (asp-net-web-api)

MSP Turkey Kickoff 2014 ASP.NET Web API and SignalR Presentation Slides, Recording and Links

I was at Microsoft Turkey office yesterday and I gave a presentation on ASP.NET Web API and SignalR in context of this year’s MSP Kickoff. This post covers where you can reach out to presentation slides, recording and several relevant links.
2014-10-19 13:44
Tugberk Ugurlu


Exciting Things About ASP.NET vNext Series: The Ultimate Guide

As of today, I am starting a new blog post series about ASP.NET vNext. To kick things off, I would like to lay out the resources about ASP.NET vNext here which is probably going to be an ultimate guide on ASP.NET vNext.
2014-10-03 11:49
Tugberk Ugurlu


Web development experience with .NET has never seen a drastic change like this since its birth day. Yes, I’m talking about ASP.NET vNext :) I have been putting my toes into this water for a while now and as of today, I am starting a new blog post series about ASP.NET vNext (with hopes that I will continue this time :)). To be more specific, I’m planning on writing about the things I am actually excited about this new cloud optimized (TM) runtime. Those things could be anything which will come from ASP.NET GitHub account: things I like about the development process, Visual Studio tooling experience for ASP.NET vNext, bowels of this new runtime, tiny little things about the frameworks like MVC, Identity, Entity Framework.

To kick things off, I would like to lay out the resources about ASP.NET vNext here. Enjoy them and start discovering what is coming up for the web development with .NET :)

Getting Started Material

Here and There ASP.NET vNext

Development Environment and Tooling Experience

Deployment

Deep Dive

MVC Specific

Badass Repositories

KRuntime: The core of the ASP.NET vNext. Compilation, bootstraping, package discovery and all other core stuff is handled here. Do not miss on this one!

kvm: K Runtime version manager which works on Windows and Unix based systems.

MVC: Written from scratch MVC framework on top of ASP.NET vNext. This new framework unifies the efforts on ASP.NET MVC and ASP.NET Web API. So, all is in one now.

HttpAbstractions: Contains HTTP abstractions for ASP.NET vNext such as HttpRequest, HttpResponse. Also contains IApplicationBuilder and types to create your application's hosting pipeline.

Home: ASP.NET vNext Home repository where you can get a head start on ASP.NET vNext really quickly. Its README file gives you a nice guide to get your machine up and running with the new tools. It also contains tiny samples which you can run and see how things are working in no time.

KestrelHttpServer: This repo contains a development web server for ASP.NET vNext based on libuv.

Configuration: Configuration is a framework for accessing Key/Value based configuration settings in an application.

Caching: Contains libraries for caching for ASP.NET vNext. Another sign that everything is now composable.

Options: Options is a framework for accessing and configuring POCO settings. Tiny thing that makes me happy that even this thing is thought of.

SignalR-Server: ASP.NET SignalR is a is a new library for ASP.NET developers that makes it incredibly simple to add real-time web functionality to your applications. This repository exposes ASP.NET SignalR on top of ASP.NET vNext.

Hosting: The Hosting repo contains code required to host an ASP.NET vNext application, it is the entry point used when self-hosting an application.

Videos

INTRODUCING: The Future of .NET on the Server: Very first video on ASP.NET vNext. Join the Lesser Scotts, Hunter and Hanselman, as they introduce you to new thinking around ASP.NET and the .NET Framework. What does ASP.NET look like in 2014 and beyond? In a world of NuGets and modular frameworks, of lightweight VMs, how could ASP.NET change and get faster, leaner, meaner, and more.

DEEP DIVE: The Future of .NET on the Server: Scott Hanselman joins developer David Fowler for this Part 2 Deep Dive into what’s coming in Microsoft ASP.NET. We explore what a decoupled stack looks like, how modules plug together, what this means for performance, and more. We explore the Project codenamed “Helios” and how this new way of writing ASP.NET applications uses OWIN and plugs into IIS giving you more power and choice than ever before.

Channel 9 Live: ASP.NET Developer Q&A with Scott Hunter & Scott Hanselman: The Scotts and David Fowler answer your questions live!

The Future of ASP.NET Part I: Scott Hanselman’s awesome intro talk on ASP.NET vNext at NDC Oslo 2014 conference.

The Future of ASP.NET Part II: David Fowler and Damian Edwards Q&A session on ASP.NET vNext at NDC Oslo 2014 conference.

An Introduction to ASP.NET vNext: Awesome introduction talk by Daniel Roth at TechEd New Zealand 2014.

ASP.NET vNext 101: Another great introduction talk on ASP.NET vNext by Damian Edwards and David Fowler at dotnetConf 2014.

ASP.NET MVC 6 (now with integrated Web API!): Awesome introduction at dotnetConf 2014 by Daniel Roth on ASP.NET MVC 6 which is a new baby from head to toe. ASP.NET MVC and Web API are being combined into a single framework, ASP.NET MVC 6, for handling all of your Web UI and services. We'll learn how to use ASP.NET MVC and Web APIs in ASP.NET vNext to support connected applications for browsers, Windows Phone, Windows Store and more!

Entity Framework: Rowan Miller gives us an introduction talk at dotnetConf 2014 about Entity Framework 7 which is built on this new .NET Runtime optimized for server. Entity Framework is Microsoft's recommended data access technology for new applications in .NET. We'll explore how the current release of Entity Framework can be used to build applications. We'll also look at an early preview of EF7, a modern, lighter weight, and composable version of Entity Framework (EF) that can be used on a variety of platforms, including ASP.NET vNext, Windows Phone and Windows Store. This new version will also support targeting non-relational data stores.

ASP.NET vNext with Chris Ross: On Web Camps TV, this week Cory is joined by Chris Ross from the ASP.NET team to talk about the vNext bits of ASP.NET. The next version of ASP.NET ("ASP.NET vNext") has been redesigned from the ground up. The goal is to create a lean and composable .NET stack for building modern cloud-based apps.

ASP.NET vNext Community Standup: Meeting recordings from the weekly ASP.NET vNext Community Standup meetings, covering live community Q&A, product team discussion and the most recent updates.

ASP.NET vNext - Everything you need to know in 4 minutes!: Nice intro on new ASP.NET vNext in a short, 4 minutes video. This nicely wraps up what are the new things.

ASP.NET vNext Giriş (in Turkish): 30 minutes webcast on ASP.NET vNext by Tugberk Ugurlu in Turkish.

Dev: ASP vNext: Scott Hunter and Brady Gaster talk about ASP.NET vNext at TechEd Europe 2014

The Future of Microsoft .NET on the Server: Scott Hunter’s TechEd session on ASP.NET vNext at TechEd Europe 2014.

Podcasts

Reconciling ASP.NET vNext with Damian Edwards: Hanselman sits down with Damian Edwards and talks about ASP.NET vNext. There's been a lot of talk around ASP.NET vNext. How did development start, and what's been the thinking about how to manage a new world while still innovating on the current generation of technology? In what ways does ASP.NET vNext break from the past, and in what ways does it build on our existing power and experience?

ASP.NET vNext with Jeff Fritz: Carl and Richard chat with Jeff Fritz about ASP.NET vNext at DotNetRocks.

Evolving ASP.NET Web Development with Scott Hunter: Carl and Richard chat with Scott Hunter about how Microsoft is working to evolve web development for ASP.NET developers. Scott talks about ASP.NET vNext as well.

Herding Code 198: Damian Edwards on ASP.NET vNext, Tag Helpers and SignalR: The guys talk to ASP.NET team member Damian Edwards about ASP.NET vNext (the next version of ASP.NET), Tag Helpers, and what’s new with SignalR.

Code Samples

MusicStore: Best sample out there for ASP.NET vNext by the team. It has two projects: one is for static-rendered Music Store application and the other one is a SPA (Single Page Application). Check out this article for further information about the sample.

BugTracker: Another sample application from ASP.NET team. This one is also uses SignalR. Check out the this article for further information about this sample.

MVC Samples: Lots of tiny MVC samples that ASP.NET team is using for functional tests.

Entropy: ASP.NET vNext feature experience playground of ASP.NET team.

MvcSample.Web: ASP.NET MVC 6 sample which highlights quite a lot of its features.

KLoggy: My playground for a few cool things such as ASP.NET vNext, Gulp, Bower, AngularJS. Check it out for sure. I have big plans for this :)

conch: Nice sample on ASP.NET vNext by Mark Rendle. The repo description says "Nothing to see here. Move along". So, keep that in mind :)

vNextLanguageSupport: A sample by David Fowler that has examples of how to support different languages in the vNext project system.

AspNetVNextSamples: My repository on ASP.NET vNext samples. It’s sort of tiny right now but I’m putting this here anyway hoping that it will get big in near future.

Microsoft Turkey Summer School 2014 - ASP.NET Web API and SignalR Talk

In context of Microsoft Turkey Summer School 2014, I had a chance to give a talk on ASP.NET Web API and ASP.NET SignalR a few days ago at Microsoft Turkey Office. Here is the slides, recording video and references from the talk.
2014-08-17 12:04
Tugberk Ugurlu


Efficiently Streaming Large HTTP Responses With HttpClient

Downloading large files with HttpClient and you see that it takes lots of memory space? This post is probably for you. Let's see how to efficiently streaming large HTTP responses with HttpClient.
2014-05-11 12:56
Tugberk Ugurlu


I see common scenarios where people need to download large files (images, PDF files, etc.) on their .NET projects. What I mean by large files here is probably not what you think. It should be enough to call it large if it’s 500 KB as you will hit a memory limit once you try to download lots of files concurrently in a wrong way as below:

static async Task HttpGetForLargeFileInWrongWay()
{
    using (HttpClient client = new HttpClient())
    {
        const string url = "https://github.com/tugberkugurlu/ASPNETWebAPISamples/archive/master.zip";
        using (HttpResponseMessage response = await client.GetAsync(url))
        using (Stream streamToReadFrom = await response.Content.ReadAsStreamAsync())
        {
            string fileToWriteTo = Path.GetTempFileName();
            using (Stream streamToWriteTo = File.Open(fileToWriteTo, FileMode.Create))
            {
                await streamToReadFrom.CopyToAsync(streamToWriteTo);
            }

            response.Content = null;
        }
    }
}

By calling GetAsync method directly there, we are loading every single byte into memory. You can see this happening in a simple way by opening the Task Manager and observing the memory of the process.

2

We are calling ReadAsStreamAsync on HttpContent after the GetAsync method is completed. This will just get us the MemoryStream, so there is no point there:

Screenshot 2014-05-11 15.18.14

We need a way not to load the response body into memory and have the raw network stream so that we can pass the bytes into another stream without hitting the memory too hard. We can do it by just reading the headers of the response and then getting a handle for the network stream as below:

static async Task HttpGetForLargeFileInRightWay()
{
    using (HttpClient client = new HttpClient())
    {
        const string url = "https://github.com/tugberkugurlu/ASPNETWebAPISamples/archive/master.zip";
        using (HttpResponseMessage response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
        using (Stream streamToReadFrom = await response.Content.ReadAsStreamAsync())
        {
            string fileToWriteTo = Path.GetTempFileName();
            using (Stream streamToWriteTo = File.Open(fileToWriteTo, FileMode.Create))
            {
                await streamToReadFrom.CopyToAsync(streamToWriteTo);
            }
        }
    }
}

Notice that we are calling another overload of the GetAsync method by passing the HttpCompletionOption enumeration value as ResponseHeadersRead. This switch tells the HttpClient not to buffer the response. In other words, it will just read the headers and return the control back. This means that the HttpContent is not ready at the time when you get the control back. Afterwards, we are getting the stream and calling the CopyToAsync method on it by passing our FileStream. The result is much better:

3

Resources

Challenge of Solving an ASP.NET Web API Self-Hosting Problem: No HTTP resource was found that matches the request URI

Couple of weeks ago, one of my former coworkers ran across a very weird problem when he was prototyping on some of his ideas with ASP.NET Web API: No HTTP resource was found that matches the request URI. Let's see what this issue was all about and what is the solution.
2014-04-16 08:28
Tugberk Ugurlu


Couple of weeks ago, one of my former coworkers ran across a very weird problem when he was prototyping on some of his ideas with ASP.NET Web API. He was hosting his ASP.NET Web API application on a console application using the Microsoft.Owin.Hosting components and Microsoft.Owin.Host.HttpListener host. His solution structure was also very simple. He put all of his controllers, message handlers, filters, etc. in one class library and all the hosting logic inside the console application. The below structure was pretty similar to what he did:

Screenshot 2014-04-16 10.36.01

Console application also has very little amount of code:

class Program
{
    static void Main(string[] args)
    {
        using (WebApp.Start("http://localhost:5555/", Start))
        {
            Console.WriteLine("Started listening on localhost:5555");
            Console.ReadLine();
            Console.WriteLine("Shutting down...");
        }
    }

    static void Start(IAppBuilder app)
    {
        HttpConfiguration config = new HttpConfiguration();
        config.Routes.MapHttpRoute("DefaultHttpRoute", "api/{controller}");
        app.UseWebApi(config);
    }
}

As you can see, it's all done by the book. However, he was constantly getting 404 when he fired up the application and sent a request to /api/cars:

Screenshot 2014-04-16 10.41.50

"No HTTP resource was found that matches the request URI". It's pretty strange. After I looked into the issue for a while, I was able to figure what the problem is:

Screenshot 2014-04-16 10.45.50

Let's make this a little bit interesting and have a look at the modules loaded into the AppDomain :)

Screenshot 2014-04-16 10.49.30

Notice that the WebApiStrangeConsoleHostSample.dll was never loaded into the AppDomain because we never used it even if it's referenced. As ASP.NET Web API uses reflection to determine the controller and the action, it never finds the CarsController. To prove our point here, I'll load the assembly manually:

static void Main(string[] args)
{
    Assembly.LoadFrom(Path.Combine(Environment.CurrentDirectory, "WebApiStrangeConsoleHostSample.dll"));
    using (WebApp.Start("http://localhost:5555/", Start))
    {
        Console.WriteLine("Started listening on localhost:5555");
        Console.ReadLine();
        Console.WriteLine("Shutting down...");
    }
}

The result is a success:

Screenshot 2014-04-16 10.56.56

However, this is not an ideal solution and I bet that you never run into this issue before. Why? Because, you wise developer keep your hosting agnostic bootstrap code inside the same assembly with you core ASP.NET Web API layer and you call this inside the host application. As soon as you call a method from the core layer assembly, that assembly will be loaded into your AppDomain.

public static class WebApiConfig
{
    public static void Configure(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute("DefaultHttpRoute", "api/{controller}");
    }
}
class Program
{
    static void Main(string[] args)
    {
        using (WebApp.Start("http://localhost:5555/", Start))
        {
            Console.WriteLine("Started listening on localhost:5555");
            Console.ReadLine();
            Console.WriteLine("Shutting down...");
        }
    }

    static void Start(IAppBuilder app)
    {
        HttpConfiguration config = new HttpConfiguration();
        WebApiConfig.Configure(config);
        app.UseWebApi(config);
    }
}

There is one other potential solution to a problem which is similar to this one. That is to replace the IAssembliesResolver service as Filip did in this post.

Tags