Web 2.0과 만나다. 그 중심에서 WCF를 외치다!! It`s all about URI

Download Report

Transcript Web 2.0과 만나다. 그 중심에서 WCF를 외치다!! It`s all about URI

It’s all about URI
Web 성공의 이유 - 첫번째!
UriTemplate
- Web에서 모든 것은 URI
• System.UriTemplate
• URI(Uniform Resource Identifier) 템플릿을 나타내는 Class
• UriTemplate.Bind
• URI Template에 비워있는 Hole들을 실체 값으로 채우는 메소드
• UriTemplate.Match
• 실제 UIR와 UriTemplate을 매칭해서 값을 뽑아내는 메소드
• UriTemplateTable
• 다양한 후보 Template과 Matching할수 있는 기능을 제공
Uri baseAddress = new Uri( “http://localhost:81” );
string artist = "Led Zeppelin";
string album = "Four";
UriTemplate template =
new UriTemplate(“music/{artist}/{album}?format={format}" );
Uri boundUri = template.BindByPosition( baseAddress, artist, album, "rss" );
//boundUri:
// http://localhost:81/music/Led%20Zeppelin/Four?format=rss
UriTemplateMatch match = template.Match( baseAddress, boundUri );
Debug.Assert( match.BoundVariables[“artist”] == artist );
Debug.Assert( match.BoundVariables[“album”] == album );
Debug.Assert( match.BoundVariables[“format”] == “rss” );
Formatting
Formats Matter
• WCF and formats
• WebGet/WebInvoke supports XML, JSON, or
opaque binary formats for request/response data
• SOAP and POX were in the box in v1 
• SyndicationFeed/SyndicationItem provide rich program
ming model for dealing with RSS/ATOM data
• Usable standalone or as WCF message content
• Integrates with serialization stacks for
feed/item extensibility
Syndication
• SyndicationFeed/SyndicationItem are format-neutral
• Formatters are format-specific
• Atom10FeedFormatter
• Rss20FeedFormatter
• Or write your own…
• Syndication functionality is layered on top of WCF
• Use with WCF, or not
• Use WebHttpBinding/WebHttpBehavior with WCF
• [WebGet]
• WebServiceHost as alternative to config
AJAX and WCF
AJAXifying WCF
• [ServiceContract]/[OperationContract] as normal
• Use [WebGet] for HTTP GET operations
• [DataContract]/[DataMember] as normal
• Use WebHttpBinding + WebScriptEnablingBehavior
• Use WebScriptServiceHost as config alternative
• DataContractJsonSerializer provides stand-alone JSON seriali
zation
RESTful Web Service
Web 성공의 이유 - 두번째
플랫폼으로써의 웹! 놀라운 득세!
그럼, Web Service를
Web의 관점에서 바라보자!!
무질서..
현재 대부분의 웹 Application은
HTTP 표준 메서드들을 지키지 않고 있다!
HTTP 표준 메서드
CRUD
SQL
HTTP
Crate
INSERT
POST
Read
SELECT
GET
Update
UPDATE
PUT
Delete
DELETE
DELETE
하지만 현실은?
GET과 POST 를 여러의미로 사용!
Resource
우리가 활용할수 있는
물리적 또는 논리적 자원이나 정보
RePresentation
Real Object (실세계 객체)의 연관성, 속성들을 나타낸다.
- 리소스의 현재 상태를 표현하는 속성, 연관성, 상징..
REST
(Representation State Transfer)
Roy Fielding – REST의 아버지
An important concept in REST is the existence of resources
(sources of specific information),
each of which can be referred to using a global identifier (a URI).
In order to manipulate these resources, components of the network
(clients and servers) communicate via a standardized interface (e.g. HTTP)
and exchange representations of these resources
RESTful
RESTful - REST 의 원칙을 잘 따르는 상태..
그러면 Web 세계에 원칙이 잘 준수되는 질서있는 세상이 옵니다!
[ServiceContract]
interface ICustomer
{
//"View It"
[OperationContract]
Customer GetCustomer():
//"Do It"
[OperationContract]
Customer UpdateCustomerName( string id,
string newName );
}
[ServiceContract]
interface ICustomer
{
//"View It"
[OperationContract]
[WebGet]
Customer GetCustomer():
//"Do It“ -> HTTP POST
[OperationContract]
[WebInvoke]
Customer UpdateCustomerName( string id,
string newName );
}
[ServiceContract]
interface ICustomer
{
//"View It“ -> HTTP GET
[OperationContract]
[WebGet( UriTemplate=“{id}” )]
Customer GetCustomer( string id ):
//"Do It“ -> HTTP PUT
[OperationContract]
[WebInvoke( UriTemplate=“{id}”, Method=“PUT” )]
Customer UpdateCustomer( string id, Customer newCustom
er );
}
• [WebGet] adds GET support to [OperationContract]
• Allows target URI space to be specified as URI template
• Templates parameters mapped to method parameters
• WebOperationContext provides easy access to Web specifics
(e.g., headers, status codes)
• [WebInvoke] provides same for other
HTTP methods
• POST is default method
• Support Update/Delete method.
WCF 철학을 기억하라!
WCF is the unified programming model
for building (all types of) connected systems
on the Microsoft platform.
Unified Management
Model
(Tracing, Config,
Instrumentation)
.NET 3.0 에서는..
Service 기반의 모델이었지만
Unified Application Programming Model
(Service Model)
Unified Infrastructure Programming Model
(Channel Model)
Broad Scenario Support
Reach
WS-I BP
interop
Secure,
Reliable,
Transacted
HTTP
Durable
Queued
Messaging
High Perf
Binary/TCP
Messaging
Rich
Unified Management
Model
(Tracing, Config,
Instrumentation)
.NET 3.5 (VS2008) 에서는..
Service 안에 Web 있다!
Reach
Web
Browser
Interop
Unified Application Programming Model
(Service Model)
Unified Infrastructure Programming Model
(Channel Model)
Broad Scenario Support
Reach
Client
Support
Webstyle
Services
WS-I BP
interop
Secure,
Reliable,
Transacted
HTTP
Rich
Durable
Queued
Messaging
High Perf
Binary/TCP
Messaging
References
• WCF and Web , Steve Maine, TechED 2007 Europe
• An Introduction to RESTful Web Service, 김성안 ,
ObjectWorld 전체 세미나
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-동일조건변경허락 2.0
대한민국 라이센스에 따라 이용하실 수 있습니다.
This work is licensed under Creative Commons Korea Attribution 2.0 License.