惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

博客园 - 如是如是

将博客搬至CSDN 钱钟书夫人杨绛:《一百岁感言》 DOM无关事件 用到了反射,还不错。可以取到动态创建类的值 JounceTabRegion Jounce Blendable RestShart Post 方式传递poco给Web api Using ASP.NET Web API with ASP.NET Web Forms ASP.NET Web API MVC-REST-SilverLight 之 架构 MVC-REST-SilverLight 之 RestExample.Model.Silverlight\Customer.cs - 如是如是 MVC-REST-SilverLight 之MainPage.xaml.cs MVC-REST-SilverLight 之 ViewModels\MainViewModel.cs - 如是如是 MVC-REST-SilverLight 之Api\CustomerApi.cs - 如是如是 - 博客园 MVC-REST-SilverLight 之 Global.asax.cs MVC-REST-SilverLight 之 HttpConfiguration MVC-REST-SilverLight 之 MapServiceRoute MEF Export 和 Import 委托 设计模式-访问者
How to Migrate from WCF Web API to ASP.NET Web API
如是如是 · 2012-03-07 · via 博客园 - 如是如是

Introduction

We recently announced that WCF Web API is now ASP.NET Web API. This document provides guidance on how to migrate your existing WCF Web API code to ASP.NET Web API.

Overview

The WCF Web API abstractions map to ASP.NET Web API roughly as follows

WCF Web API

ASP.NET Web API

Service

Web API controller

Operation

Action

Service contract

Not applicable

Endpoint

Not applicable

URI templates

ASP.NET Routing

Message handlers

Same

Formatters

Same

Operation handlers

Filters, model binders

Web API Controllers

Update you service types to be web API controllers by first deriving from ApiController and renaming your service type so that the type name ends with "Controller".

Routing

You can directly map URI templates to routes by defining a route that matches the URI template path and then specifying the method name as the default value for the action route variable. The approach will result in one route per action, which depending on the number of actions may result in significant performance overhead.

To consolidate the number of routes consider refactoring your service so that there is one web API controller per resource.

 Model Binding

Model binding is a powerful feature in ASP.NET MVC (and on its way to Web Forms in ASP.NET 4.5 too). It allows you to write a method that accepts your custom object type as a parameter, and ASP.NET Web API handles mapping posted data to that parameter. It lets you focus on implementing your specifications and get out of the business of mindless (and error prone) mapping code. Here's an example, showing how a method that accepts posted data can focus on the logic of handling the data:

?

1

2

3

4

5

6

7

public HttpResponseMessage<comment> PostComment(Comment comment) 

{

    comment = repository.Add(comment);

    var response = new HttpResponseMessage<comment>(comment, HttpStatusCode.Created);

    response.Headers.Location = new Uri(Request.RequestUri, "/api/comments/" + comment.ID.ToString());

    return response;

}

Filters

Filters are a really powerful feature in ASP.NET MVC. You can use attributes to apply pre/post logic to action methods, entire controllers, or globally to all action methods. They're available in ASP.NET Web API as well, and you use the same kind of logic to both build and apply them. I worked with a sample that applied some custom attribute based validation using a global action filter, and found it really to apply my ASP.NET MVC background.