280 likes | 296 Views
Dive into Windows Communication Foundation (WCF) to migrate app logic to the cloud. Learn the ABCs of WCF, hosting options, service bindings, REST vs. SOAP, and deploying on Azure. Discover JSON formatting and implementing REST support in WCF. Start your journey into Android programming with Eclipse and Android SDK setup.
E N D
Liberate Your Apps! Philippe LeefsmaSenior Developer Consultant Autodesk Developer Network
Getting Started • Windows Communication Foundation (WCF) • http://msdn.microsoft.com/en-us/library/ms731082.aspx • Cloud Hosting Providers • http://www.windowsazure.com • http://aws.amazon.com
WCF Web ServicesMigrate your Application logic to the cloud…
What is WCF ? • Windows Communication Foundation is Microsoft's next-generation programming platform and runtime system for building, configuring and deploying network-distributed services (Source MSDN)
WCF Basics - ABC • "ABC" is the key to understand how a WCF service is composed: • "A" stands for Address: Where is the service? • "B" stands for Binding: How do clients talk to the service? • "C" stands for Contract: What can the service do for a client?
Data Contract [DataContract] publicclassAdnMaterial { [DataMember] publicstring Name { get; set; } [DataMember] publicdouble Price { get; set; } [DataMember] publicstring Manufacturer { get; set; } }
Service Contract [ServiceContract] publicinterfaceIMaterialSrv { [OperationContract] AdnMaterial[] GetMaterials(); [OperationContract] AdnMaterialGetMaterial( stringmaterialName); [OperationContract] boolPostMaterial( AdnMaterialmaterial); }
Implementing Services publicclassMaterialSrv : IMaterialSrv { publicMaterialSrv() { //Constructor... } publicAdnMaterial[] GetMaterials() { //Implementation... } //Implementation other methods... }
Service bindings • A binding binds a service contract implementation to an address. This includes: • Choosing an appropriate transport protocol • Choosing how messages are encoded • Defining how security works
Hosting a Service • The following options are available to host a WCF Service: • Self-hosting in any managed .NET application Winform, WPF, console Application, … • Hosting in a Windows service • Hosting in IIS ASP.Net Direct Hosting
HTTP Requests • World Wide Web (WWW) • Web of resources • Resources reference each other • Resources can be of many types (e.g., documents, images, services, html pages) • URI identifies resources (Uniform Resource Identifier) • HTTP used to access resources 9 methods (a.k.a. verbs): GET, PUT , POST , DELETE , … HEAD, OPTIONS, TRACE, CONNECT, PATCH
SOAP • SOAP stands for Simple Object Access Protocol • Protocol for exchanging structured information through Web Services • Relies on XML for its message format, and Application Layer protocols like HTTP or SMTP for message transmission
REST • REST stands for Representational State Transfer • REST is an architectural style that exploits HTTP protocol • Provides an easier way of data access comparing with SOAP • Good solution for interoperability betweenweb servicesand mobile platforms or browsers
REST Web Services Why REST? REST is a lightweight alternative to SOAP SOAP: <?xmlversion="1.0"?> <soap:Envelopexmlns:soap="http://www.w3.org/2003/12/soap-envelope"> <soap:Bodypb="http://www.adesk.com/memberdb"> <db:GetDeveloperDetails> <db:DeveloperID>12345</db:DeveloperID> </db:GetDeveloperDetails> </soap:Body> </soap:Envelope> SOAP REST http://www.adesk.com/memberdb/DeveloperDetails/12345
SOAP vs REST SOAP • Supports only GET and POST • All data is in the xml message Resource to access Function to execute REST • Uses all HTTP verbs: GET, POST, PUT, DELETE, … • Resource is identified by URI • Function is identified by the HTTP verb
JSON • JSON (JavaScript Object Notation) is a lightweight data exchange format • JSON is a text format easy for humans to read and write and fast for machines to parse and generate • One of the most popular exchange format in web services at the moment
JSON vs XML { "Manufacturer":"ADN", "Name":"Steel", "Price":"100.0" } <?xml version="1.0" encoding="UTF-8" ?> <Manufacturer>ADN</Manufacturer> <Name>Steel</Name> <Price>100.0</Price>
Adding REST Support in WCF [ServiceContract] publicinterfaceIMaterialSrv { [OperationContract] [WebInvoke( Method = "GET", UriTemplate = "/Material/{materialName}", ResponseFormat = WebMessageFormat.Json)] AdnMaterialGetMaterial(stringmaterialName); [OperationContract] [WebInvoke( Method = "POST", UriTemplate = "/Material", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] boolPostMaterial(AdnMaterialmaterial); }
Getting Started with Android programming • Install Eclipse http://www.eclipse.org/downloads/ • Install Android SDK http://developer.android.com/sdk/installing.html • Get started with Android development http://developer.android.com/guide/index.html
Getting Started with iOS programming • Install Xcode Downloadable from App Store Mac application Includes SDK and iOS Simulator • Get started with iOS development https://developer.apple.com/devcenter/ios/index.action