FT10: Driving Experiences via Services Using the Microsoft ... - MSDN

fishnibblersspongyΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 7 μήνες)

61 εμφανίσεις

Driving Experiences via Services
Using the
Microsoft .NET
Framework

Ron Jacobs

Sr. Technical Evangelist

Microsoft Corporation

Experience

Share, explore, question my world

With others

When and how I want

Even right now

On whatever device I have at hand


How do we move from a
PC oriented experience
to a multi
-
device
experience?

Services Drive Experiences

Services Drive Experiences

Services

The Web of Services
should work the way
the Web of Pages works

WCF

WCF

Model

Service

public

class

Conference
:
DataService
<
ConferenceDataEntities
>

{


// This method is called only once to initialize service
-
wide policies.


public

static

void

InitializeService
(
DataServiceConfiguration

config
)


{


config.SetEntitySetAccessRule
(
"*"
,
EntitySetRights
.AllRead
);


config.DataServiceBehavior.MaxProtocolVersion

=
DataServiceProtocolVersion
.V2;


}

}




Data Services

Implications


Fast and Easy


REST over Model (backed by Database)


Also supports Services


Power to the caller

Constrain


public

class

Conference
:
DataService
<
ConferenceDataEntities
>

{


// This method is called only once to initialize service
-
wide policies.


public

static

void

InitializeService
(
DataServiceConfiguration

config
)


{


config.SetEntitySetAccessRule
(
"*"
,
EntitySetRights
.AllRead
);


config.DataServiceBehavior.MaxProtocolVersion

=





DataServiceProtocolVersion
.V2
;


config.SetEntitySetPageSize
(
"Sessions"
, 10);


config.SetEntitySetPageSize
(
"Speakers"
, 5);


}

}




Route

private

void

RegisterRoutes
()

{


DataServiceHostFactory

factory =



new

DataServiceHostFactory
();


RouteTable
.Routes.Add
(


new

ServiceRoute
(
"Conference"
,



factory
,
typeof
(
Conference
)));

}


Routed Data Services

WCF

Resources

Resource


public

class

SessionData

{


public

int

ID {
get
;
set
; }


public

string

Title {
get
;
set
; }


public

DateTime
? Date {
get
;
set
; }


public

string

Speaker {
get
;
set
; }

}



Resources

URI

Resource URI

URI Template

HTTP

Method

Operation

Session/

GET

Get all sessions

Session/{id}

GET

Get one session

Session/{id}/Speaker

GET

Gets speaker for session

Session/

POST

Add a new session

Session/{id}

PUT

Update a session

Session/{id}

DELETE

Delete

Resources

URI

Service

Web HTTP Services

Step 1


Create Service

Step 2


Implement Service

Step 3


Attribute for WCF

Step 3


Attribute for WCF

HTTP GET = “~/Sessions/
GetSession?id
=123”

Step 3


Attribute for WCF

HTTP GET = “~/Sessions/123”

Step 3


Attribute for WCF

HTTP GET = “~/
Sessions?start
=5&count=7”

Step 4


Add Routes

public

class

Global

:
System.Web.
HttpApplication

{


void

Application_Start
(
object

sender,
EventArgs

e)


{


RegisterRoutes
();


}



private

void

RegisterRoutes
()


{


WebServiceHostFactory

factory =



new

WebServiceHostFactory
();


RouteTable
.Routes.Add
(


new

ServiceRoute
(
"Sessions"
,




factory
,
typeof
(
SessionService
)));


}

}


No .SVC file!

Step 5


Configure

<
system.serviceModel
>


<
standardEndpoints
>


<
webHttpEndpoint
>


<
standardEndpoint



automaticFormatSelectionEnabled
=
"
true
"



helpEnabled
=
"
true
"

/>


</
webHttpEndpoint
>


</
standardEndpoints
>


<
serviceHostingEnvironment



aspNetCompatibilityEnabled
=
"
true
"

/>

</
system.serviceModel
>


.NET 4 Web HTTP
Services

Incarnate

WF4 Coordination

Q&A


Blog


http://blogs.msdn.com/rjacobs


Twitter: @
ronljacobs


endpoint.tv


http://channel9.msdn.com/shows/Endpoint
/


10
-
4 Show


http://channel9.msdn.com/shows/10
-
4
/