Create RESTful WCF Service API: Step By Step Guide



Similar documents
WCF Service Creation With C#

Getting Started Guide for Developing tibbr Apps

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

Administering Jive Mobile Apps

Developing ASP.NET MVC 4 Web Applications Course 20486A; 5 Days, Instructor-led

How to Scale out SharePoint Server 2007 from a single server farm to a 3 server farm with Microsoft Network Load Balancing on the Web servers.

Fairsail REST API: Guide for Developers

Web Services. with Examples. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

AppDev OnDemand Microsoft Development Learning Library

Intranet Website Solution Based on Microsoft SharePoint Server Foundation 2010

Sage CRM. Sage CRM 2016 R1 Mobile Guide

SharePoint Server Quick Start Guide for Single Server Farms

ArcGIS Web Mapping. Sam Berg, esri

Integration Overview. Web Services and Single Sign On


Cloud Powered Mobile Apps with Azure

Developing ASP.NET MVC 4 Web Applications MOC 20486

A REST API for Arduino & the CC3000 WiFi Chip

Business Application Development Platform

CT30A8902 Service Oriented Architecture Exercises

70-487: Developing Windows Azure and Web Services

1 of 9 12/27/2012 5:01 PM

Developing ASP.NET MVC 4 Web Applications

REST vs. SOAP: Making the Right Architectural Decision

Web Testing. Main Concepts of Web Testing. Software Quality Assurance Telerik Software Academy

Integration of Hotel Property Management Systems (HPMS) with Global Internet Reservation Systems

maximizing IT productivity

Leveraging Cloud Storage Through Mobile Applications Using Mezeo Cloud Storage Platform REST API. John Eastman Mezeo

HTML5. Turn this page to see Quick Guide of CTTC

Thomas Röthlisberger IT Security Analyst

Cloud Elements! Marketing Hub Provisioning and Usage Guide!

New Features of SharePoint 2013

10 Game-changing Features in Visual Studio 2013 for the ASP.NET Developer

Getting Started with AWS. Hosting a Static Website

The end. Carl Nettelblad

STK Terrain Server Installation Guide

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

This three-day instructor-led course provides students with the tools to extend Microsoft Dynamics CRM 4.0.

INTERNET PROGRAMMING AND DEVELOPMENT AEC LEA.BN Course Descriptions & Outcome Competency

Building and Using Web Services With JDeveloper 11g

WebsitePanel Installation Guide

Table of Contents. Oxygen Web Client Uploading my files Versioning my files Deleting my files... 36

Web Cloud Architecture

A Sample OFBiz application implementing remote access via RMI and SOAP Table of contents

Jive Connects for Openfire

Creating XML Report Web Services

T320 E-business technologies: foundations and practice

Whats the difference between WCF and Web Services?

Introduction to the AirWatch Browser Guide

Integrating SalesForce with SharePoint 2007 via the Business Data Catalog

Getting Started With Your LearnDevNow Learning

XML Processing and Web Services. Chapter 17

This module provides an overview of service and cloud technologies using the Microsoft.NET Framework and the Windows Azure cloud.

Team: May15-17 Advisor: Dr. Mitra. Lighthouse Project Plan Client: Workiva Version 2.1

To install Multifront you need to have familiarity with Internet Information Services (IIS), Microsoft.NET Framework and SQL Server 2008.

Developer Tutorial Version 1. 0 February 2015

Cross-domain Identity Management System for Cloud Environment

CLOUD COMPUTING & WINDOWS AZURE

SAV2013: The Great SharePoint 2013 App Venture

THE NEW DIGITAL EXPERIENCE

Implementing Mobile Thin client Architecture For Enterprise Application

SHARPCLOUD SECURITY STATEMENT

R i o L i n x s u p p o r r i o l i n x. c o m 1 / 3 0 /

Enabling REST Services with SAP PI. Michael Le Peter Ha

Upgrading Your Development Skills to SharePoint 2013 Course 55014A; 5 Days, Instructor-led

Search help. More on Office.com: images templates

Operational Decision Manager Worklight Integration

Design and Functional Specification

Hybrid for SharePoint Server Search Reference Architecture

Expanded contents. Section 1. Chapter 2. The essence off ASP.NET web programming. An introduction to ASP.NET web programming

How To Test Your Web Site On Wapt On A Pc Or Mac Or Mac (Or Mac) On A Mac Or Ipad Or Ipa (Or Ipa) On Pc Or Ipam (Or Pc Or Pc) On An Ip

v Devolutions inc.

Software Development Interactief Centrum voor gerichte Training en Studie Edisonweg 14c, 1821 BN Alkmaar T:

The Beginner s Guide to G-Lock WPNewsman Plugin for WordPress: Installation and Configuration

Dynamic Web Programming BUILDING WEB APPLICATIONS USING ASP.NET, AJAX AND JAVASCRIPT

Contents Release Notes System Requirements Administering Jive for Office

Professional Profile

SAML and OAUTH comparison

How To Install Powerpoint 6 On A Windows Server With A Powerpoint 2.5 (Powerpoint) And Powerpoint On A Microsoft Powerpoint 4.5 Powerpoint (Powerpoints) And A Powerpoints 2

Joseph M Conaty Software Engineer

Secure Coding SSL, SOAP and REST. Astha Singhal Product Security Engineer salesforce.com

branddocs Technology edocument Solutions V V

Angel Learning Management System Introductory Tutorial for Students

How To Build A Web App

WISE-4000 Series. WISE IoT Wireless I/O Modules

MS 20487A Developing Windows Azure and Web Services

IFS CLOUD UPLINK INSTALLATION GUIDE

Extending Microsoft Dynamics CRM 4.0

Building native mobile apps for Digital Factory

Zend Server 4.0 Beta 2 Release Announcement What s new in Zend Server 4.0 Beta 2 Updates and Improvements Resolved Issues Installation Issues

WEB SERVICES FOR MOBILE COMPUTING

UOFL SHAREPOINT ADMINISTRATORS GUIDE

MS Enterprise Library 5.0 (Logging Application Block)

Using EMC Documentum with Adobe LiveCycle ES

ISTEC.MIP Measurement Data Integration Platform

Cloud Elements ecommerce Hub Provisioning Guide API Version 2.0 BETA

Course MS55077A Project Server 2013 Development. Length: 5 Days

Transcription:

9,193,791 members and growing! Email Password Sign in Join Lost password? Home Articles Quick Answers Discussions Zones Features Community Help! Search site» Platforms, Frameworks & Libraries» Windows Communication Foundation» WWS API Create RESTful WCF Service API: Step By Step Guide By ashutosh k. shukla 30 Aug 2010 Article.NET3.5 C# WCF C#4.0.NET4 Licence CPOL First Posted 30 Aug 2010 Views 143,485 Downloads 7,304 Bookmarked 148 times See Also More like this More by this author Step by Step Guide to create Restful WCF service API in ASP.NET and C# Article Browse Code Stats Revisions (4) Alternatives 4.93 (74 votes) 116 Download source - 9.29 KB Introduction Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for your services, enabling you to expose CLR types as services, and to consume other services as CLR types. In this article, I am going to explain how to implement restful service API using WCF 4.0. The Created API returns XML and JSON data using WCF attributes. What is REST? Based on the Roy Fielding theory "Representational State Transfer (REST), attempts to codify the architectural style and design constraints that make the Web what it is. REST emphasizes things like separation of concerns and layers, statelessness, and caching, which are common in many distributed architectures because of the benefits they provide. These benefits include interoperability, independent evolution, interception, improved scalability, efficiency, and overall performance." Actually only the difference is how clients access our service. Normally, a WCF service will use SOAP, but if you build a REST service, clients will be accessing your service with a different architectural style (calls, serialization like JSON, etc.). REST uses some common HTTP methods to insert/delete/update/retrieve information which is below: 1. GET - Requests a specific representation of a resource 2. PUT - Creates or updates a resource with the supplied representation 3. DELETE - Deletes the specified resource 4. POST - Submits data to be processed by the identified resource Why and Where to Use REST? Few days back, I was writing a service which was supposed to be accessed by heterogeneous language/platform/system. It can be used by iphone, Android, Windows Mobile,.NET web application, JAVA or PHP. Using web service, it was bit complex for me to expose it to everyone using uniform system. Then we decided to use REST, which was easily espoused over cloud. This was a great example which shows the capability of SIMPLE RESTful SERVICE :). Below are some points which will help you to understand why to use the RESTful services. 1. Less overhead (no SOAP envelope to wrap every call in) 2. Less duplication (HTTP already represents operations like DELETE, PUT, GET, etc. that have to otherwise be represented in a SOAP envelope). 3. More standardized - HTTP operations are well understood and operate consistently. Some SOAP implementations can get finicky. 4. More human readable and testable (harder to test SOAP with just a browser). Hot News: Windows 8 review: Yes, it's that bad The Code Project Insider. Free each morning. Related Articles CREATE RESTful WCF Service API Using POST: Step By Step Guide 4 Simple Steps to Consume WCF Service using Silverlight Step by Step Guide to Delicious OAuth API First Step to REST via WCF 6 Steps to Enable Transactions in WCF Create a REST service with WCF and consume it using jquery Basic Authentication on a WCF REST Service A Step by Step WCF Small Program For Beginners Restful Crud Operation on a WCF Service Create REST Service using WCF Eight steps to enable Windows authentication on WCF BasicHttpBinding Step by Step SharePoint Server 2010 Installation Guide Nine simple steps to enable X.509 certificates on WCF WPF/Silverlight: Step By Step Guide to MVVM Digest Authentication on a WCF REST Service Step by Step Guide to Silverlight 4 Command Binding Consuming a WCF / ASMX / REST Service using jquery Step By Step Guide to Factory Pattern Client Activated Object (CAO) Creation RESTful Web Services: A Quick- Start How-to Guide - Part 1 4 Steps to Enable Instrumentation in WCF 1/7

4. More human readable and testable (harder to test SOAP with just a browser). 5. Don't need to use XML (well, you kind of don't have to for SOAP either but it hardly makes sense since you're already doing parsing of the envelope). 6. Libraries have made SOAP (kind of) easy. But you are abstracting away a lot of redundancy underneath as I have noted. Yes, in theory, SOAP can go over other transports so as to avoid riding atop a layer doing similar things, but in reality just about all SOAP work you'll ever do is over HTTP. Step by Step Guide Generally, a developer is scared to use WCF because of a lot of confusing configuration. I will try to use minimum configuration so that it will be easier to understand for us. We will develop Restful WCS API in 6 steps. So let s start now. STEP 1 First of all launch Visual Studio 2010. Click FILE->NEW->PROJECT. Create new "WCF Service Application". STEP 2 Once you create the project, you can see in solution that By Default WCF service and interface file are already created. Delete By default created file as we will create our own interface and WCF service file. STEP 3 Now right click on solution and create one new WCF service file. I have given name to the service file as RestServiceImpl.svc. 2/7

STEP 4 As I explained at the start of the article that we will be writing an API which can return data in XML and JSON format, here is the interface for that. In IRestServiceImpl, add the following code: In the above code, you can see two different methods of IRestService which are XMLData and JSONData. XMLData returns result in XML whereas JSONData in JSON. STEP 5 Open the file RestServiceImpl.svc.cs and write the following code over there: STEP 6 3/7

Now let s move to configuration part which is the last one. There will be two basic parts of the configurations file which we must have to understand. <services> Collapse Copy Code This part contains information about the End Point. Below are the code details. <behaviors> Collapse Copy Code This part contains details about service and endpoint behavior. And that s it. Our Restful WCF service is ready for test purposes. Service Ready to Test Now Now I launch the application in the browser to see the result. I launch this service in Internet Explorer and my URL is now http://localhost:35798/restserviceimpl.svc. Now if I use http://localhost:35798/restserviceimpl.svc/xml/123 URL, I get the following response on the browser which is an XML format and that was my task to achieve. Now if I use http://localhost:35798/restserviceimpl.svc/json/123 URL, I get the following response on the browser which is an XML format and that was my task to achieve. 4/7

Hope the article is useful for the community. Comments, suggestions and criticisms are all welcome. History License 30 th August, 2010: Initial post This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL) About the Author ashutosh k. shukla Software Developer (Senior) http://mrashu.blogspot.com/ Singapore A versatile person having 6.0 Years of IT Industry experience in software development on.net Technology presently leading the team successfully. Member Follow on Twitter Article Top Sign Up to vote Poor Excellent Vote Comments and Discussions You must Sign In to use this message board. Search this forum Go Profile popups Noise Medium Layout Expand Posts & Replies Per page 10 Update wonderful! I give you a 5! Refresh Janilane First Prev Next 21hrs 21mins ago Thanks for sharing your knowledge, this really helped when the net is so full of explanation but not much How-Tos. Re: wonderful! I give you a 5! Thanks. I am glad that my article is useful for you. ashutosh k. shukla 20hrs 58mins ago Great write up,how to add security? Member 9300316 9:18 13 Aug '12 Thanks for your great tutorial, How can I add security in to this and host this on IIS? 5/7

Re: Great write up,how to add security? ashutosh k. shukla 16:11 15 Aug '12 Actually i have not added security there in the sample example. But you can add this easily as WCF supports multiple security modes. You can get those details over here : http://msdn.microsoft.com/en-us/library/ff405740.aspx[^] Thanks Ashu Simple & great PREMSONBABY 22:34 9 Aug '12 Really appreciate the effort. A sample code should be like this fully backed ready to eat cake. Good work. Regards, Premson. Re: Simple & great Thanks ashutosh k. shukla 23:23 9 Aug '12 Web.config Strascina 14:26 8 Aug '12 I've been following these steps (outlined in http://www.codeproject.com/articles/105273/create-restful-wcf-service-api-step-by- Step-Guide) and got my service to work well. I've been trying to implement it into an existing ASP.net solution and have been unable to get everything to work. This "new" webservice works but my other applications don't. I'm thinking maybe something is wrong in my solution web.config file (that's the error I'm getting, anyway). I've put the contents of the web.config stuff you've outlined (the whole piece) in the file. Could there be another attribute I'm missing that gets a webservice to work with non-webservice stuff? Any help you could provide would be great. Re: Web.config ashutosh k. shukla 16:09 8 Aug '12 There may be many reason behind this issue. Can u please explain a bit more with example? I will try to solve this. Re: Web.config Strascina 4:26 9 Aug '12 Thanks for the speedy reply - I'm in Colorado (the time is 8:25 am on 8/9/2012). I have a asp.net (c#) application I built using the 3.5 framework that does some DB reads\writes and does a lot of HTML stuff. I built this REST application as a stand alone item (for development and testing) and now want to bring it into my other app. I first changed the target framework on the main app to 4.0. Then I brought in the REST project and added the service model references. I modified the solution web.config - added the service model stuff from the REST app. It compiles successfully but my main app will not fire, but the REST app does. Re: Web.config ashutosh k. shukla 5:05 9 Aug '12 I think this code will only work for framework 4.0. It will not work on 3.5. Last Visit: 18:00 31 Dec '99 Last Update: 17:14 16 Aug '12 1 2 3 4 5 6 7 8 9 10 11 Next» 6/7

General News Suggestion Question Bug Answer Joke Rant Admin P ermalink A dvertis e P rivac y M obile Layout: fixed A rtic le C opyright 2 0 1 0 by as hutos h k. s hukla Web0 4 2.5.1 2 0 8 1 2.1 Las t U pdated 3 0 A ug 2 0 1 0 fluid E verything els e C opyright C odep rojec t, 1 9 9 9-2 0 1 2 T erms of U s e 7/7