没有合适的资源?快使用搜索试试~ 我知道了~
首页ASP.NET MVC 4 and the Web API.pdf
资源详情
资源评论
资源推荐


For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
Download from Wow! eBook <www.wowebook.com>

v
Contents at a Glance
Foreword ������������������������������������������������������������������������������������������ xi
About the Author ���������������������������������������������������������������������������� xiii
About the Technical Reviewer ��������������������������������������������������������� xv
Acknowledgments ������������������������������������������������������������������������� xvii
Chapter 1: ASP�NET MVC as a Service Framework ■ ������������������������� 1
Chapter 2: What is RESTful? ■ ����������������������������������������������������������� 9
Chapter 3: Designing the Sample REST API ■ ���������������������������������� 23
Chapter 4: Building the Environment and Creating ■
the Source Tree �������������������������������������������������������������������������������� 43
Chapter 5: Controllers, Dependencies, and Managing ■
the Database Unit of Work ������������������������������������������������������������ 63
Chapter 6: Securing the Service ■ ��������������������������������������������������� 89
Chapter 7: Putting It All Together ■ ����������������������������������������������� 103
Index ���������������������������������������������������������������������������������������������� 127

1
Chapter 1
ASP.NET MVC as
a Service Framework
In the years since the first release of the .NET Framework, Microsoft has provided a
variety of approaches for building service-oriented applications. Starting back in 2002
with the original release of .NET, a developer could fairly easily create an ASP.NET
ASMX-based XML web service that allowed other .NET and non-.NET clients to call it.
Those web services implemented various versions of SOAP, but were only available for
use over HTTP.
In addition to web services, the 1.0 release of .NET provided support for Remoting.
This allowed developers to write services that weren’t necessarily tied to the HTTP
protocol. Similar to ASMX-based web services, .NET Remoting essentially provides object
activation and session context for client-initiated method calls. The caller uses a proxy
object to invoke methods, and the .NET runtime handles serialization and marshaling of
data between the client’s proxy object and the server’s activated service object.
Towards the end of 2006, Microsoft released .NET 3.0, which included the Windows
Communication Foundation (WCF). WCF not only replaced ASMX web services and
.NET Remoting, but also took a giant step forward in the way of flexibility, configurability,
extensibility, and support for more recent security and other SOAP standards.
For example, with WCF, a developer can write a non-HTTP service that supports
authentication with SAML tokens, and host it in a custom-built Windows service. These
and other capabilities greatly broaden the scenarios under which .NET can be utilized to
build a service-oriented application.
MOre ON WCF
If you’re interested in learning more about WCF, I recommend reading either
Programming WCF Services by Juval Lowy [O’Reilly, 2007] or Essential Windows
Communication Foundation by Steve Resnick, Richard Crane, and Chris Bowen
[Addison-Wesley Professional, 2008]. Both of these books are appropriate for
WCF novices and veterans alike, as they cover the spectrum from basic to
advanced WCF topics.

CHAPTER 1 ■ ASP.NET MVC AS A SERVICE FRAMEWORK
2
If you need to set up communication between two applications, whether they are
co-located or separated by thousands of miles, rest-assured WCF can do it. And if its
out-of-the-box features don’t suffice, WCF’s tremendous extensibility model provides
ample opportunity for plugging in just about anything you can think of.
And this is where we will take a bit of a left turn, off the evolutionary path of ever
greater capability and flexibility, and towards something simpler and more targeted at a
small set of specific scenarios.
In the Land of JavaScript and Mobile Devices
During much of the growth of the Internet over the past two-plus decades, web sites and
pages have relied on server-side code for anything but basic HTML manipulation. But
more recently, various AJAX-related tools and frameworks—including (but not limited to)
JavaScript, jQuery, HTML5, and some tricks with CSS—have given rise to the need for
services that are less about complex enterprise applications talking to each other and
more about web pages needing to get and push small amounts of data. In these cases,
communicating with a service over HTTP is pretty much a given, since the web sites
themselves are HTTP applications. Further, security options available from within a
browser are vastly simpler than those of an out-of-browser application, and thus support
for all of the various security-related SOAP standards is not required of the service.
In addition to simpler protocol and security needs, web pages typically communicate
with other applications and services using text-based messages rather than binary-formatted
messages. As such, a service needs only to support XML or JSON serialization.
Beyond web applications, today’s smartphones and tablets have created a huge
demand for services in support of small smart-client mobile applications. These services
are very similar in nature to those that support AJAX-enabled web sites. For example,
they typically communicate via HTTP; they send and receive small amounts of text-based
data; and their security models tend to take a minimalist approach in order to provide
a better user experience (i.e., they strive for less configuration and fewer headaches for
users). Also, the implementation of these services encourages more reuse across the
different mobile platforms.
In short, there is now a desire for a service framework that, out-of-the-box, provides
exactly what is needed for these simple text-based HTTP services. While WCF can be used
to create such services, it is definitely not configured that way by default. Unfortunately,
the added flexibility and configurability of WCF make it all too easy to mess something up.
And this is where the ASP.NET MVC Framework comes into the picture.
Advantages of Using the MVC Framework
Once you know that, under certain scenarios, you aren’t interested in many of the
capabilities of WCF, you can start thinking of a framework like ASP.NET MVC—with fewer
service-oriented bells and whistles—as being advantageous. In this section, you’ll look in
detail at a few of these.
剩余140页未读,继续阅读





安全验证
文档复制为VIP权益,开通VIP直接复制

评论0