Telerik Software Academy Web Services & Cloud.

Slides:



Advertisements
Similar presentations
Michael S. Chan xLM Solutions, LLC
Advertisements

WCF Intro Scott Reed Owner - Brain Hz Software Instructor – DevelopMentor
Web Services Nasrullah. Motivation about web service There are number of programms over the internet that need to communicate with other programms over.
Zoiner Tejada Hershey Technologies. About Zoiner Tejada.
 Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.
1 Nordjyllands Erhvervakademi Windows Communication Foundation Introduction –.Net foundations –Communication Protocols –SOA tenets WCF –Basics –Contracts.
Latest techniques and Applications in Interprocess Communication and Coordination Xiaoou Zhang.
Introduction to Web Services
Windows Communication Foundation and Web Services.
Darryl Burling Developer Evangelist Microsoft The age of connected applications Whats new in VS2008 WCF Background: WS*,.Net 3.0 and WCF ABC’s & improvments.
Adam Dille CS526 – Spring  Advances in Microsoft’s service offerings  ASMX vs. WCF  Latest WCF Improvements (.NET 4.0)  No in-depth study of.
The Microsoft Technical Roadshow 2006 Windows Communication Foundation Mike Taulty Developer & Platform Group Microsoft Ltd
1 Web Services Visual C# 2008 Step by Step Chapter 30.
Module 13: WCF Receive Adapters. Overview Lesson 1: Introduction to WCF Receive Adapters Lesson 2: Configuring a WCF Receive Adapter Lesson 3: Using the.
Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc.
Getting Started with WCF Windows Communication Foundation 4.0 Development Chapter 1.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Introduction to Windows Communication Foundation Ruwan Wijesinghe.
[Title of the course] WCF
Agenda What Is the Windows Communication Foundation? How Does It Work? How Do I Use and Deploy It? Bindings Addresses Contracts How to host WCF services.
Module 14: WCF Send Adapters. Overview Lesson 1: Introduction to WCF Send Adapters Lesson 2: Consuming a Web Service Lesson 3: Consuming Services from.
Microsoft Visual Studio 2010 Muhammad Zubair MS (FAST-NU) Experience: 5+ Years Contact:- Cell#:
CSCI 6962: Server-side Design and Programming Web Services.
James Holladay, Mario Sweeney, Vu Tran. Web Services Presentation Web Services Theory James Holladay Tools – Visual Studio Vu Tran Tools – Net Beans Mario.
1 UCN 2012 Why use distributed (client / server) applications? To connect tiers within the same application... –client & server is both.NET assemblies.
Microsoft Visual Studio 2010 Muhammad Zubair MS (FAST-NU) Experience: 5+ Years Contact:- Cell#:
Intro to WCF From the beginning and uses Steve AppRochester.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
.Net and Web Services Security CS795. Web Services A web application Does not have a user interface (as a traditional web application); instead, it exposes.
Random Logic l Forum.NET l Web Services Enhancements for Microsoft.NET (WSE) Forum.NET ● October 4th, 2006.
Mahesh Krishnan, Senior Consultant, Readify Slide 1.
2 Productive Windows Communication Foundation Jeremy Boyd Mindscape MSDN Regional Director – New Zealand SOA315.
INT-9: Implementing ESB Processes with OpenEdge ® and Sonic ™ David Cleary Principal Software Engineer.
ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP.
Week Six : Writing Web Services Aims: Creating and Consuming student’s first Web Services Learning Outcomes: Familiarity with VS.NET for creating and consuming.
Web Services Security with Visual Studio 2005 Muhammad Saqib Ilyas
Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation.
Agenda What Is the Windows Communication Foundation? How Does It Work? How Do I Use and Deploy It? Bindings Addresses Contracts How to host WCF services.
.NET Mobile Application Development XML Web Services.
Dhananjay Kumar MVP-Connected System 1. WCF  Agenda What is WCF ? Why WCF? Address, Binding, Contract End Points Hosting Message Patterns Programming.
Christian Weyer thinktecture.
The SOAP Story Martin Parry Developer & Platform Group Microsoft Ltd
1 G52IWS: Web Services Description Language (WSDL) Chris Greenhalgh
Windows Communication Foundation António Cruz Freelancer (SAPO/PT.COM)
Shani Raba Team Leader & Software Architect
OE-NIK HP Advanced Programming WCF WCF SOAP service, host, client Exception handling (NOT required)
OE-NIK HP Advanced Programming Web services Standards and protocols Using web services Using web services with asynchronous calls.
Introduction to Web Services Srinath Vasireddy Support Professional Developer Support Microsoft Corporation.
O VERVIEW OF SOA AND WCF Jinaldesai.net – My Thouths And Learnings.
Windows Communication Foundation and Web Services
Jim Fawcett CSE681 – SW Modeling & Analysis Spring 2005
Windows Communication Foundation
Segments Introduction: slides 2–7 10 minutes
Windows Communication Foundation
Windows Communication Foundation
Window Communication Foundation
Windows Communication Foundation
Distribution of functionality Webservice using WCF
Windows Communication Foundation and Web Services
Windows Communication Foundation
INTRODUCTION TO WEB SERVICES CS 795. What is a Web Service ? Web service is a means by which computers talk to each other over the web using HTTP and.
Implementing a service-oriented architecture using SOAP
אפליקציות אסינכרוניות ל-Windows 10
Windows Communication Foundation (WCF)
The SOAP Story Martin Parry Developer & Platform Group Microsoft Ltd
Distributed System using Web Services
Techniques to Invoke Web Services from SAS
SOAP web services in Microsoft Azure
WCF Data Services and Silverlight
Presentation transcript:

Telerik Software Academy Web Services & Cloud

1. WCF – Quick Introduction 2. Creating a WCF Service  Creating a Service Contract  Implementing the Service Contract  Configuring the Service 3. Hosting WCF Services (Self-Hosting and in IIS) 4. Consuming WCF Services Through Proxies  Generating Proxies with the svcutil.exe  Adding Service Reference in Visual Studio 2

5. The WCF Test Client (WcfTestClient.exe) 6. Asynchronous Calls to WCF Services 7. WCF RESTful Services 3

Quick Introduction

Programming Model 5

 Service contract  Describes the service methods, parameters, and returned result  Data contract  Describe the data types used in the contract and their members 6 [ServiceContract] public interface ISumator { [OperationContract] [OperationContract] int Sum(int a, int b); int Sum(int a, int b);} [DataContract] public class Person { [DataMember] [DataMember] string Name {get; set;} string Name {get; set;}}

 Binding  Transport – HTTP, TCP, MSMQ, …  Channel type – one-way, duplex, request-reply  Encoding – XML, JSON, binary, MTOM  WS-* protocols – WS-Security, WS-Addressing, WS-ReliableMessaging, WS-Transaction, …  Addressing   net.tcp://someOtherURI  net.msmq://stillAnotherURI 7

Step by Step

 WCF is а powerful Microsoft technology stack for the SOA world  Three steps to use WCF:  Create a WCF Service  Service contract, data contract, implementation  Host the WCF Service  Several hosting options: IIS, standalone, …  Consume (use, invoke) the WCF service from a client application 9

 To create a WCF Web Service use one of the following VS templates:  WCF Service Application  WCF Service Library  Three steps to create WCF services:  Define one or more interfaces describing what our service can do (operations)  Implement those interfaces in one or more classes (implementation)  Configure the service (XML configuration file) 10

Step 1: Defining a Service Contract

 In order for a WCF service to be used you have to define a service contract  Defines the functionality offered by the service to the outside world  Describes to potential users how they communicate with the service  The WSDL description of the service depends on the service contract  To define a contract create an interface marked with the [ServiceContract] attribute 12

 Extensive use of attributes:  ServiceContractAttribute – for the exposed service interface  OperationContractAttribute – for the contract methods that a client can see and use  DataContractAttribute – for any classes used as parameters in a method or returned as a result from a method  DataMemberAttribute – the properties of those classes visible to the clients 13

14 [ServiceContract] public interface IServiceTest { [OperationContract] [OperationContract] string GetData(int value); string GetData(int value); [OperationContract] [OperationContract] CompositeType GetDataUsingDataContract( CompositeType GetDataUsingDataContract( CompositeType composite); CompositeType composite);}[DataContract] public class CompositeType { bool boolValue = true; bool boolValue = true; string stringValue = "Hello"; string stringValue = "Hello"; …}

Step 2: Implementing the Service Contract

 Once a contract is created, the functionality offered by the service has to be implemented  We need a class that implements the interface that defines the contract  For example: 16 public class ServiceTest : IServiceTest { public string GetData(int value) public string GetData(int value) { return string.Format("You entered: {0}", value); return string.Format("You entered: {0}", value); } …}

Step 3: Configuring the Service

 WCF services are visible to the outside world through the so called endpoints  Each endpoint consists of three parts:  Address – the URL of the endpoint  Can be relative to the base address  Binding – the protocol over which the communication with the service is made  Contract – which service contract is visible through this endpoint 18

 Configure endpoints in two ways  In the application settings  By a special section in the application configuration file  Web.config / App.config  The most frequently used approach  By C# code: 19 selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService"); new WSHttpBinding(), "CalculatorService");

 The contains many configuration options  Two very important elements:  – defines services and endpoints  elements are configured by their behaviorConfiguration attribute  Points to an existing behavior  They have endpoint elements  The endpoints are configured through attributes 20

21 <service name="WcfServiceTest.ServiceTest" <service name="WcfServiceTest.ServiceTest" behaviorConfiguration= behaviorConfiguration= "WcfServiceTest.ServiceTestBehavior"> "WcfServiceTest.ServiceTestBehavior"> <endpoint address="" binding="wsHttpBinding" <endpoint address="" binding="wsHttpBinding" contract="WcfServiceTest.IServiceTest"> contract="WcfServiceTest.IServiceTest"> </services>

 The serviceBehaviors section defines behaviors (configurations) for services  Services are configured by specifying which behavior they use  Many sub-elements  serviceMetadata – metadata options  serviceDebug – debug options  dataContractSerializer – controls the way data contracts are serialized  … 22

23 <behavior <behavior name="WcfServiceTest.ServiceTestBehavior"> name="WcfServiceTest.ServiceTestBehavior"> <serviceDebug <serviceDebug includeExceptionDetailInFaults="false"/> includeExceptionDetailInFaults="false"/> </serviceBehaviors>

Live Demo

 The WCF model has many hosting options  Self hosting  In a console application, Windows Forms or WPF application  Mainly for development and testing  Windows Service  In IIS 5.1 (or later), 6.0 or 7.0  Used in production environment  Windows Process Activation Service (WAS) 26

 Hosting WCF services in IIS is a typical scenario  IIS itself handles creation and initialization of the ServiceHost class  We need a *.svc file to host in IIS  Base content of the.svc file:  It has the ServiceHost directive  Tells IIS in what language is the service written and the main class of the service 27 Language="C#" Debug="true" Service="WcfServiceTest.ServiceTest" %> Service="WcfServiceTest.ServiceTest" %>

 The code for the service (the contract and the class implementing it) can be stationed in three places  Inline – following the ServiceHost directive  In an assembly in the Bin directory  As.cs files in the App_Code directory  You must set the necessary permissions in order for IIS to have access to your files 28

Live Demo

 Hosting of the service is managed by the ServiceHost class  Located in System.ServiceModel namespace  You must have reference the System.ServiceModel.dll assembly  In self-hosting scenarios we initialize and start the host ourselves 30 ServiceHost selfHost = new ServiceHost( typeof(CalculatorService), typeof(CalculatorService), new Uri(" new Uri("

Live Demo

 The WCF Test Client is a GUI tool for playing with WCF services  Enables users to input test parameters, submit that input to the service, and view the response  WCF Test Client ( WcfTestClient.exe ) is part of Visual Studio  Can be started from the VS Command Prompt  Typical location:  Starts on [F 5 ] in VS for WCF Service Libraries 32 C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\

Live Demo

 To consume a WCF service we make use of the so called proxy classes  Those look like normal classes in the code  When you call a method of the proxy it makes a SOAP request to the service  When the service returns the SOAP result the proxy transforms it to a. NET type 35 Client Proxy WCF Service

 Proxy classes can be generated using the svcutil.exe tool  The simplest form (from the command line):  The service must be configured to allow getting its metadata  Via WS-Metadata-Exchange or Disco  The result is the AddService.cs class and the output.config file 36 svcutil

 There are many options to this command line  You can set the names of the generated files  You can set the namespace  Asynchronous methods generation  The AddService.cs must be visible in our project  The contents of the output.config must be merged with the app.config / web.config  No automerging is supported 37

 In Visual Studio you can also use the "Add Service Reference" option in a project  It's a wrapper around svcutil.exe  A set of XML config files is generated 38

 When adding a service reference  Entries are added to the web.config or app.config respectively  Don't manipulate those entries manually unless you know what you're doing 39

 Using proxy classes is identical to using normal classes but produces remote calls  You instantiate the proxy class  Then call its methods  Call the Close() method of the proxy  If the interface of the service changes you have to regenerate the proxy class 40 AddServiceClient addSevice = new AddServiceClient(); new AddServiceClient(); int sum = addService.Add(5, 6);

Live Demo

 Sometimes a service call takes too long and we don't need the result immediately  We can make asynchronous calls in two ways  By using a delegate  The delegate has this functionality built-in  By generating the proxy class with the " svcutil /async " option  Creates asynchronous methods as well  When adding a service reference in Visual Studio there is an option under Advanced Settings 43

 When the proxy class is generated to support asynchronous calls we get few new methods  For every OperationContract method we get the BeginXXX() and EndXXX() methods  You can make use of the callback method 44 public void static Main() { AsyncCallback cb = new AsyncCallback(CallFinished); AsyncCallback cb = new AsyncCallback(CallFinished); service.BeginLongProcess(params, cb, service); service.BeginLongProcess(params, cb, service);} private void CallFinished(IAsyncResult asyncResult) { Console.WriteLine("Async call completed."); Console.WriteLine("Async call completed.");}

Live Demo

Creating and Consuming RESTful WCF Services

 In the.svc file add the following:  Use special binding in Web.config :  Use URL mapping in the service contract 47 <standardEndpoint defaultOutgoingResponseFormat="Json" helpEnabled="true" /> helpEnabled="true" /> [OperationContract] [WebInvoke(Method = "GET", UriTemplate = "Category/{categoryID}")] UriTemplate = "Category/{categoryID}")] Category FindCategoryByID(string categoryID);

Live Demo

Questions?

1. Create a simple WCF service. It should have a method that accepts a DateTime parameter and returns the day of week (in Bulgarian) as string. Test it with the integrated WCF client. 2. Create a console-based client for the WCF service above. Use the "Add Service Reference" in Visual Studio. 3. Create a Web service library which accepts two string as parameters. It should return the number of times the second string contains the first string. Test it with the integrated WCF client. 4. Host the latter service in IIS. 5. Create a console client for the WCF service above. Use the svcutil.exe tool to generate the proxy classes. 50