OE-NIK HP Advanced Programming WCF WCF SOAP service, host, client Exception handling (NOT required)

Slides:



Advertisements
Similar presentations
Web Services & EAI.
Advertisements

WCF Intro Scott Reed Owner - Brain Hz Software Instructor – DevelopMentor
SOAP.
Zoiner Tejada Hershey Technologies. About Zoiner Tejada.
 Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.
Windows Communication Foundation and Web Services.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 42 Web Services.
Tutorials 2 A programmer can use two approaches when designing a distributed application. Describe what are they? Communication-Oriented Design Begin with.
Oct 21, 2004CS573: Network Protocols and Standards1 IP: Addressing, ARP, Routing Network Protocols and Standards Autumn
X.509 support in WCF Exploring support for X.509 Certificates in Microsoft’s Windows Communication Foundation Paul Cormier UCCS CS591 Fall 2009.
The Microsoft Technical Roadshow 2006 Windows Communication Foundation Mike Taulty Developer & Platform Group Microsoft Ltd
Hands-On Microsoft Windows Server 2003 Administration Chapter 5 Administering File Resources.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc.
WCF Services in Nutshell A Tutorial using WCF Mr. Michael Arnwine WCF using Service Oriented Architecture (SOA) and “Restful” Service.
Getting Started with WCF Windows Communication Foundation 4.0 Development Chapter 1.
Introduction SOAP History Technical Architecture SOAP in Industry Summary References.
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.
Grid Computing, B. Wilkinson, 20043b.1 Web Services Part II.
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 Apache. 2 Module - Apache ♦ Overview This module focuses on configuring and customizing Apache web server. Apache is a commonly used Hypertext Transfer.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
Tom Castiglia Hershey Technologies
Web Services Week 7 Aims: A detailed look at the underlying mechanisms for communication between web services Objectives: SOAP, WSDL, UDDI.
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.
Web Services. ASP.NET Web Services  Goals of ASP.NET Web services:  To enable cross-platform, cross- business computing  Great for “service” based.
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.
Telerik Software Academy Web Services & Cloud.
Getting Started with OPC.NET OPC.NET Software Client Interface Client Base Server Base OPC Wrapper OPC COM Server Server Interface WCF Alternate.
Cairngorm Microarchitecture. Pronunciation Cairngorm (kârn gôrm) n. yellowish-brown variety of quartz, especially found in Scottish Cairngorm mountain.
Web Services Error Handling and Debugging. Agenda Simple SOAP faults Advanced SOAP faults SOAP headers and faults Error handling From a Service Perspective.
ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
ICM – API Server & Forms Gary Ratcliffe.
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.
Intro to Web Services Dr. John P. Abraham UTPA. What are Web Services? Applications execute across multiple computers on a network.  The machine on which.
.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.
1 G52IWS: Web Services Description Language (WSDL) Chris Greenhalgh
DEVELOPING WEB SERVICES WITH JAVA DESIGN WEB SERVICE ENDPOINT.
SOAP, Web Service, WSDL Week 14 Web site:
Shani Raba Team Leader & Software Architect
Distributed Computing & Embedded Systems Chapter 4: Remote Method Invocation Dr. Umair Ali Khan.
OE-NIK HP Advanced Programming Web services Standards and protocols Using web services Using web services with asynchronous calls.
O VERVIEW OF SOA AND WCF Jinaldesai.net – My Thouths And Learnings.
The Mechanics of HTTP Requests and Responses and network connections.
Windows Communication Foundation and Web Services
Jim Fawcett CSE681 – SW Modeling & Analysis Spring 2005
Windows Communication Foundation
IP: Addressing, ARP, Routing
Windows Communication Foundation
Distribution of functionality Webservice using WCF
Windows Communication Foundation and Web Services
WEB API.
אפליקציות אסינכרוניות ל-Windows 10
Creating a Distributed System with Remote Procedure Calls and Web Services Ch.5 B.Ramamurthy 2/17/2019 B.Ramamurthy.
Chapter 42 Web Services.
Techniques to Invoke Web Services from SAS
WCF Data Services and Silverlight
Exceptions and networking
Presentation transcript:

OE-NIK HP Advanced Programming WCF WCF SOAP service, host, client Exception handling (NOT required)

OE-NIK HP Advanced Programming WCF WCF SOAP service, host, client Exception handling (NOT required)

V1.0 IP-based alternatives to call a method TCP/UDP (or theoretically even ICMP) –Send and receive a sequence of bytes, must handle the format –Difficult to implement, very fast, almost zero overhead SOAP –Pre-defined SOAP XML formats to define and call the service methods and transmit various data types (array, list, object) –Arbitrary protocol to transmit the XML messages, usually HTTP –Very easy to implement, relatively slow, big overhead –We will use this one REST –Custom JSON format to transmit unique objects (rarely XML) –We rarely need complex parameters, in this case we use HTTP POST to send a JSON object (rarely XML) –Typically we only need the method name and string/int parameters, thus most of the method calls can be represented as HTTP GET requests –The answer is typically JSON (rarely XML) –Easy to implement, medium speed, medium overhead 3 OE-NIK HP

V1.0 Windows Communication Foundation An advanced API to develop and use distributed systems/services Exists since.NET 3.0, hides the physical communication Integrates all the technologies that existed before in.NET –XML-webservices, DCOM,.NET remoting, etc... –This means: SOAP, since the beginning! –Later: REST (REST+Entity Framework: WCF Data Services!) –The actual TCP/HTTP communication is hidden 4 OE-NIK HP Client applicationWCF host ProxyWCF service

V1.0 WCF ABC To facilitate the communication, the following data are necessary: –Address: for accessing the service Protocol:// [:port]/path e.g. –Binding: to specify the network protocol, encoding, transport layer E.g. WSHttpBinding for web services NetTcpBinding for non-HTTP communication –Contract: to describe the accessible methods All of these are described in the WSDL... We don’t want to create WSDL by hand! 5 OE-NIK HP

Advanced Programming WCF WCF SOAP service, host, client Exception handling (NOT required)

V1.0 Parts of a WCF application WCF service –Usually a DLL that contains the descriptor interface and the actual service implementation –We use attributes to mark the roles of the actual interfaces/classes/methods –The WSDL is automatically generated! WCF service host –This application hosts (executes) the service (i.e. creates the instance, etc.) –With SOAP this can be any.NET executable (console, WPF) –With REST this is typically a web application / web page hosted by IIS (this is also possible with soap) WCF client –Uses the service via a proxy class –Can be any.NET application 7 OE-NIK HP

V1.0 Creating a WCF SOAP service Create a WCF Service Library project –This generates the skeleton – always use automatic rename! ServiceContract –An interface that describes the methods of the service –Every accessible method must be marked with the attribute OperationContract –Should specify a unique namespace E.g.. [ServiceContract(Namespace=" DataContract –Every class that is sent/received –Usually contains no methods (they cannot be transferred...) –Public properties are marked with the DataMember attribute Service class –Implements the ServiceContract interface –Actual service implementation 8 OE-NIK HP

V1.0 To test the service Visual Studio can create a WCF Test Client that can be used to test the service methods The App.config is required  we only have the app.config near the DLL if we want tot test the service. Otherwise: rename/move Use the Invoke button to call the method Check the actual SOAP communication 9 OE-NIK HP

V1.0 App.config An XML file With WCF: Contains the service descriptors –ABC: Address, Binding, Contract –Service Behaviors, MEX (metadata) configuration –Usually automatically updated Edit with wizard –Right click on App.config; Edit WCF configuration –Services: class name –Host: IP address –Endpoints: ABC and MEX data 10 OE-NIK HP

V1.0 App.config 11 OE-NIK HP ABC MEX endpoint Behaviors for the MEX

V1.0 Creating a service host New project (console app), add reference to System.ServiceModel Move the App.Config into this project from the DLL The host creates an instance using the type as a parameter –ServiceHost host = new ServiceHost(typeof(EightBallService)) The service is closed on keypress/enter key –using: automatic release of resources, without the GC 12 OE-NIK HP

V1.0 Creating a service client Same process that we used last lesson Host must be running when we add the service reference Run separately (or: multiple startup projects) 13 OE-NIK HP

V1.014 OE-NIK HP Exercises Create a service that allows us to get/set the ratings for restaurants (store everything in XML files) –GetRestaurants(), GetRatings(int restaurant), AddRating(int restaurant, int rating, string comment) –Use LINQ to XML Create a service that allows us to store and query log events in a central location –One entry = software name, entry text, datetime –Store the entries in an XML file –The Read(string programname) method should process this XML

V1.0 Solution 1.Create the service 1.WCF Service Library -> LogServiceDLL 2.Contract -> ILogService 3.Functionality -> LogService 2.Create the host 1.Console Application -> LogServiceHost 2.ABC ->Move the App.Config file here 3.Create the client 1.Do NOT add reference to the DLL!!! (same name, same properties, different classes!) 2.Console Application -> LogServiceTester 15 OE-NIK HP

Advanced Programming WCF WCF SOAP service, host, client Exception handling (NOT required)

V1.0 Exceptions in WCF If unhandled exceptions occur, the exception is thrown to the client –CommunicationException - the server did not provide a meaningful reply; this might have been caused due to a contract mismatch, a premature session shutdown or an internal server error. –The communication channel is closed To keep the channel open, we must use SOAP-based exception handling: –returnUnknownExceptionsAsFaults / [ServiceBehavior(IncludeExceptionDetailInFaults=true)]: Every exception will be transmitted as fault messages INSECURE –FaultException (FaultContract needed in addition to the usual ABC) 17 OE-NIK HP

V1.0 SOAP Fault Typical SOAP error fields: –faultcode: required string. Usually starts with the text “server” or “client”, depending on where the error originated from –faultstring: readable error message –faultactor: the exact fault location In WCF, we have to create a FaultException instance Every class can be put into a SOAP fault (the FaultContract attribute is required) –new FaultException (myfe,faultReason,faultCode); myfe: encapsulated exception instance faultReason: same as faultString faultCode: same as faultCode 18 OE-NIK HP

V1.0 FaultContracts The WCF contract (descriptor interface) must contain the information required for the possible exceptions [OperationContract] [FaultContract(typeof(SomeCustomFaultException))] double GetBMI(double weight, double height); –If the contract has no FaultContract, then everything will be thrown as UnknowFaultException –The FaultContract will be put into the WSDL Classes used with the FaultContract attributes must be also included in the WSDL – DataContract + DataMember [DataContract] public class SomeCustomFaultException { [DataMember] public string Message{get;set;} } 19 OE-NIK HP

V1.0 Throwing and catching faults Create the descriptor instance Create a FaultException instance Specify the faultReason and the faultCode –SomeCustomFaultException error = new SomeCustomFaultException(); error.Message = "Zero value passed for height“; throw new FaultException ( error, new FaultReason(ex.StackTrace), new FaultCode("Client.DivideByZero")); In the client, catch the exception the usual way –catch (System.ServiceModel.FaultException fex) 20 OE-NIK HP