10 Ways to Build Web Services in .NET

Using 10 different web frameworks and client libraries to build and use web services in .NET
Course info
Rating
(476)
Level
Intermediate
Updated
Sep 25, 2013
Duration
6h 2m
Table of contents
Course Introduction
ASMX Web Services
WCF Web Services
WCF AJAX Web Services
WCF REST Web Services
WCF Data Web Services
MVC3 Web Services
MVC4 Web Services
FubuMVC Web Services
ServiceStack Web Services
Nancy Web Services
Course Review
Description
Course info
Rating
(476)
Level
Intermediate
Updated
Sep 25, 2013
Duration
6h 2m
Description

With the new-found popularity of single-page applications, smartphone applications, and multi-device experiences, web services are becoming increasingly important in the infrastructure of the web and applications. This course will present a few different ways that web services may be created within the .NET framework, ranging from ASMX web services all the way to MVC4 Web API. We will also look at a handful of options available to connect to those web services from a client application. Both Microsoft.NET framework as well as open source options will be explored.

About the author
About the author

Chad McCallum is a software developer with 7 years of .NET experience. After graduating from SIAST Kelsey Campus, he's come back to his hometown and started HackREGINA, a hackathon aimed at strengthening the developer community while coding and drinking beer. Currently focusing on single-page applications with JavaScript.

More from the author
Section Introduction Transcripts
Section Introduction Transcripts

Course Introduction
Hi. I'm Chad McCallum. Welcome to the Pluralsight course for 10 Ways to Build Web Services in. NET. Within this course we'll be exploring 10 different ways to build a simple Create, Read, Update, Delete CRUD-based web service and also 10 different ways to connect to that service in a. NET client application. So, to start, let's quickly review what a web service is. A web service is a service for something that receives input processes that input and returns the appropriate output, but because it's a Web Service it's accessed using web-standard methods, which in most cases it means just using the hypertext transfer protocol, HTTP. And the powerful thing with Web Services is clients or consumers of a web service don't need to know anything about the platform, the object model, programming language, anything on the server side to actually connect to and use a web service. They just need to know how to send and receive hypertext transfer protocol, which the large majority of programming languages now a days have an HTTP client that can be used by client applications. So, simply by having a library that can connect to the web and send and receive data, we can use any web service that's published by any company, private or public, and create applications using their functionality. There are a few different types of web services we'll be reviewing in the modules to follow. The first one is a Remote Procedure Call or RPC style web service. The idea behind RPC is that you're calling methods, but instead of calling methods on an object located in local memory, you're actually calling them over the web against an HTTP server hosted somewhere. To do this, we use the Simple Object Access Protocol also known as SOAP. SOAP is the standard used to represent method calls and return values. SOAP is an XML-based format, which represents the method that you're executing, as well as the parameters you're sending to the server for that method, and it also wraps the return value or the response from the server in response to executing that particular method. In conjunction with SOAP, we'll use the Web Service Definition Language, WSDL document, to communicate kind of a contract or a standard for what's expected for input and output. The WSDL document lists to a client exactly what input, what parameters, what methods you can execute on the client and exactly what you can expect from the server when it comes to output from those methods. The second type of web service is a Web API service. This is a service that relies more on existing HTTP standards to send and receive data as opposed to using SOAP or WSDL documents to create a separate transfer protocol. Data in Web API services is usually sent and received in XML or JSON, but there are a number of different formats that can be supported as well. Web API services are structured so that multiple services can be combined into single applications. You've probably seen this on your smart phone or on web applications where apps are taking data from Twitter and Facebook and other APIs and Google Maps and a bunch of different Web API web services and creating individual applications from those. Those are usually referred to as mashup applications. Web API services are structured and geared towards supporting those scenarios. Web API services can also be more resource focused as opposed to action focused. When we're dealing with remote procedure call style of services, you're usually communicating a specific method with specific arguments, whereas Web API services can focus more on dealing with individual resources. So, the difference there could be with an RPC style service you might call GetCustomerByID, whereas a Web API service might instead give you a different URL to deal with customers, /customers for example, and then you specify the ID as a GET parameter or another part of the route. In that case, you're dealing more with a specific resource, the actions you can execute against that resource instead of just executing explicit actions like you would with RPC services. A subset of Web API services is known as REST, RESTful services, or Representational State Transfer services. REST services are very similar to the Web API services, but they have a few more strict guidelines when it comes to the architecture and the access of their particular service. For example, REST services use HTTP verbs to perform actions with resources. So, to create a new resource, you would use a POST verb; to read data from the server, you'd use the HTTP GET verb; to update, you'd use either PUT or PATCH; and to delete a resource, you'd use the DELETE verb. And there are a few other HTTP verbs that can be supported in addition to that as well. REST also has a pretty strong focus on stateless resources and clean URLs. Stateless resources meaning you can send the exact same request to the server, and regardless of the request you sent before or after that, it should be able to deal with that individual request. And clean URLs we have an example of below here whereas normally if you were talking to a RPC or a Web API self- service you might go to /GetCustomerByID passing some other parameter as GET variables into your method. A RESTful approach would refer to each one of those variables as part of the resource. So, for example, if you wanted a customer at position 5 or a customer ID 5, we go /customers/5. And then if we wanted invoices belonging to that resource we would add a /invoices to the end of that as well. So, a little more information about the projects we'll be working on in our module. Each module we'll be creating a simple Create, Read, Update, Delete CRUD web service. Within that web service, I have already supplied the data layer and transport objects just so we can focus simply on the web service creation. Each module in the course will use a different web service framework, so there are 10 overall that we'll be reviewing. Within each module we'll also be working on a console application to connect to the web service that we just created. Again, with the console app I've tried to abstract as much of the application logic away as possible, so we'll simply implement a data layer class to abstract the web service from the actual application logic. And, again, within each module we'll be trying to use a different web service client framework as well so you can see all of the different ways in. NET we can connect to web services. As we said, we'll be looking at a different web service and web client technology in each module, so here's a quick reference for all of the modules if you want to skip to something specific. The first module we'll be using ASMX web services and using the Add Service Reference dialog in Visual Studio to connect to that web service. Module 3 we'll be making a WCF style web service and using the WCF Test Client to connect to it. In module 4, we'll be making a WCF AJAX web service, and with that there's a generated JavaScript Proxy class, which we'll use inside of a web page client to connect to it. Module 5 we'll be talking about WCF REST and using the standard. NET WebClient and HttpWebRequest objects to connect to that service. Module 6 we'll be creating a WCF Data Service and using the included OData Client to communicate with it. In module 7, we'll be switching to MVC3 and using the. NET 4. 0 HttpClient to make asynchronous connections to our web server. In module 8, we'll be using MVC4 and Web API on the server and an open source library called EasyHTTP to connect to it. In module 9, we'll be using the open source FubuMVC framework and the open source Spring. NET REST Client on the client application. Module 10 we'll be using the ServiceStack on the server to create our web service and the included ServiceStack Client library to connect to it. And finally, in module 11 we'll be using Nancy to create our web service and the open source RestSharp library on the client to connect to our new web service.