.NET Fundamentals ASP.NET Web Services December 11, 2003.

Slides:



Advertisements
Similar presentations
Web Service Architecture
Advertisements

Session 6 Module 2 Calling a Web Service from an ASP.NET Web Page.
Siebel Web Services Siebel Web Services March, From
Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.
31242/32549 Advanced Internet Programming Advanced Java Programming
Web Service Ahmed Gamal Ahmed Nile University Bioinformatics Group
Topics Acronyms in Action SOAP 6 November 2008 CIS 340.
Web Services Darshan R. Kapadia Gregor von Laszewski 1http://grid.rit.edu.
Web Services Nasrullah. Motivation about web service There are number of programms over the internet that need to communicate with other programms over.
Building and Using Web Services with ASP.NET Rob Howard Program Manager.NET Framework Team Microsoft Corp.
Presentation 7 part 2: SOAP & WSDL. Ingeniørhøjskolen i Århus Slide 2 Outline Building blocks in Web Services SOA SOAP WSDL (UDDI)
Windows Communication Foundation and Web Services.
Grid Computing, B. Wilkinson, 20043a.1 WEB SERVICES Introduction.
XML Web Services ASP.NET. Overview of Web Services (Page 1) Web Service – Part or all of a Web application that is publicly exposed so that other applications.
Chapter 12 Extending Web Applications. ASP.NET 2.0, Third Edition2.
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.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
Web Services Michael Smith Alex Feldman. What is a Web Service? A Web service is a message-oriented software system designed to support inter-operable.
Processing of structured documents Spring 2003, Part 6 Helena Ahonen-Myka.
TP2653 Adv Web Programming SOAP and WSDL. SOAP Simple Object Access Protocol – Lightweight XML-based messaging protocol – A protocol for accessing a Web.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
ASP.NET The.NET Framework. The.NET Framework is Microsoft’s distributed run-time environment for creating, deploying, and using applications over the.
SOAP Tutorial Ching-Long Yeh 葉慶隆 Department of Computer Science and Engineering Tatung University
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
Web Services (SOAP, WSDL, and UDDI)
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
James Holladay, Mario Sweeney, Vu Tran. Web Services Presentation Web Services Theory James Holladay Tools – Visual Studio Vu Tran Tools – Net Beans Mario.
Web Server Administration Web Services XML SOAP. Overview What are web services and what do they do? What is XML? What is SOAP? How are they all connected?
Lecture 15 Introduction to Web Services Web Service Applications.
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#:
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.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
.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.
Web Services. Abstract  Web Services is a technology applicable for computationally distributed problems, including access to large databases What other.
1 Web Service Description Language (WSDL) 大葉大學資工系.
Chapter 10 Intro to SOAP and WSDL. Objectives By study in the chapter, you will be able to: Describe what is SOAP Exam the rules for creating a SOAP document.
XML Web Service. Overview of XML Web Service ASP.NET XML Web services enable you to remotely access the properties and methods of classes across a network.
1 Web Services Web and Database Management System.
XML and Web Services (II/2546)
S imple O bject A ccess P rotocol Karthikeyan Chandrasekaran & Nandakumar Padmanabhan.
Web Services Error Handling and Debugging. Agenda Simple SOAP faults Advanced SOAP faults SOAP headers and faults Error handling From a Service Perspective.
Kemal Baykal Rasim Ismayilov
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.
Chapter 7: Creating and Consuming XML Web Services Understanding XML Web Services Creating XML Web Services Deploying and Discovering XML Web Services.
Understanding Web Applications Lesson 4. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Web Page Development Understand Web.
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.
Introduction to Web Services Presented by Sarath Chandra Dorbala.
1 G52IWS: Web Services Description Language (WSDL) Chris Greenhalgh
DEVELOPING WEB SERVICES WITH JAVA DESIGN WEB SERVICE ENDPOINT.
Net-centric Computing Web Services. Lecture Outline  What is Web Service  Web Service Architecture  Creating and using Java Web Services  Apache Axis.
Beginning 자바 웹 서비스 SOAP 강미란 Cyber-Infrastructure Research Lab Konkuk University.
SOAP, Web Service, WSDL Week 14 Web site:
Introduction to Web Services Srinath Vasireddy Support Professional Developer Support Microsoft Corporation.
Software Architecture Patterns (3) Service Oriented & Web Oriented Architecture source: microsoft.
Jim Fawcett CSE681 – SW Modeling & Analysis Spring 2005
Sabri Kızanlık Ural Emekçi
A Web Services Journey on the .NET Bus
WEB SERVICES.
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
Chapter 23 – ASP.NET Outline 23.1 Introduction NET Overview
Web Server Administration
Presentation transcript:

.NET Fundamentals ASP.NET Web Services December 11, 2003

Homework or Other Questions?

Review Class Goals

Class Goal #1 Provide an overview of the.NET Architecture and it’s Major Components –Programming Languages –ADO.NET –ASP.NET –Web Services –XML Integration

Class Goal #2 Understand the.NET Frameworks as an Object Oriented, Strongly Typed, Computing Environment

Class Goals #3 Work with various.NET Framework components –Common Language Runtime (CLR) –.NET Framework Class Library (FCL) –Assemblies –Strong Names –The Global Assembly Cache (GAC) –ADO.NET –ASP.NET –Web Services

Class Goals #4 Develop a basic fluency programming in C#

Agenda  Tonight and Monday December 15 th Web Services Presentation Web Services Class Exercise Web Service Class/Homework Project –Start tonight –Complete Monday (or by Friday December 19 th ) –Teams of two or three ? Also help on Monday with any homework assignment or other questions (All homework due by Friday December 19 th )

Topics – December 11, 2003 Distributed Computing ASP.NET Web Services SOAP (Simple Object Access Protocol) WSDL (Web Services Description Language) Let’s write a web service with Visual Studio.NET Debugging an ASP.NET Web Application XML Web Services Local vs. Web Projects Deploying Web Applications Internet Information Services (IIS)

ASP.NET Web Services

Web Services Web Services are a new way of performing remote procedure calls over HTTP Web Services make use of SOAP (Simple Object Access Protocol). SOAP is an XML-based standard that details how method calls are made over HTTP in a reproducible manner Web Services are completely described using WSDL (Web Service Description Language) Web Services are able to use the full array of C# and.NET techniques over the server.

What is SOAP?

SOAP (Simple Object Access Protocol)

Remote objects can give a program almost unlimited power over the Internet, but most firewalls block non-HTTP requests. SOAP, an XML-based protocol, gets around this limitation to provide intraprocess communication across machines.

SOAP (Simple Object Access Protocol) Traditionally, HTTP is the application level protocol used between web-clients and web servers. Web clients are now more than browsers requesting HTML. HTTP is fairly simple, restricted to requesting and sending resources with GET, PUT and POST, but is not designed for flexible exchange of data between applications. The Simple Object Access Protocol (SOAP) aims to fix this by defining a protocol that any application can use to communicate and exchange data with any other application

SOAP (Simple Object Access Protocol) SOAP is a simple, lightweight XML-based protocol for exchanging structured and type information on the Web. SOAP uses XML Grammar tailored for exchanging web service data.NET Web Service usually sends SOAP messages over HTTP SOAP Protocol was originally developed by Compaq, HP, IBM, Lotus, Microsoft, and others

SOAP (Simple Object Access Protocol) To achieve maximum flexibility, SOAP uses XML syntax to format its content. SOAP is designed to be: –As simple as possible –Provide a minimum functionality Therefore SOAP is both modular and flexible. However, the SOAP protocol does not include anything on security or transactions

SOAP (Simple Object Access Protocol) Since SOAP is an application level protocol, it can run on any transport e.g. TCP. The protocol defines a messaging framework that contains no application or transport semantics. As a result, the protocol is modular and very extensible. Since SOAP messages are XML, which is plain text, they can easily pass through firewalls SOAP is not limited to name/value pairs as HTTP-GET and HTTP-POST are, but can send complex objects including datasets, classes, and other objects. SOAP focuses on the ability to send messages from a sender to a recipient. The use of SOAP as an RPC mechanism is purely a byproduct of this functionality. RPC-like behavior is achieved by sending messages in both directions.

SOAP (Simple Object Access Protocol) One negative to using SOAP is that messages tend to be verbose, because of the nature of XML. If bandwidth or transmission performance is an issue, HTTP-GET or HTTP-POST maybe better choices..NET Frameworks provides a class, the SoapHttpClientProtocol for using the SOAP protocol in your clients..NET Frameworks provides a number of classes for interacting with HTTP protocol, including a hierarchy of classes for SOAP, HTTP-GET and HTTP-POST client protocols, all deriving from WebClientProtocol and HttpWebClientProtocol.

Structure of a SOAP Message SOAP Envelope SOAP Header SOAP Body Header parts Payload SOAP Fault

Structure of a SOAP message The Envelope is the top-level container representing the message. The Header is a generic container for added features to a SOAP message in a decentralized manner. SOAP defines attributes to indicate who should deal with a feature and whether understanding is optional or mandatory. The Body is a container for mandatory information intended for the ultimate message receiver. SOAP defines one element for the body to report errors, called a SOAP Fault.

SOAP styles SOAP can have 2 styles –Document-style SOAP, which is used to simply exchange XML data. –RPC-style SOAP, which is used to make an RPC request and get it’s response. Both styles of SOAP messages look the same, but the body of an RPC style SOAP message has some rules around how requests/responses are tagged.

A Basic SOAP Message <SOAPENV:Envelope xmlns:SOAPENV=" This message has just an envelope and a body. The SOAP envelope namespace has to be specified to make this a valid SOAP message. This shows a document-style SOAP message.

SOAP Faults and.NET exceptions Any.NET exception that is thrown on the web service side is automatically wrapped in a SOAPException, so it can be serialized as a SOAP Fault. The InnerException chain is lost. One way to transmit meaningful information is to catch exceptions at the Web Service, and re-throw a SOAPException, with additional information stuck into the Details element of the SOAPException class. The receiving side can parse out the SOAP fault detail.

SOAP Specification

Web Services

Web Services. A web service is an application that exposes a Web- accessible API (i.e. a class method). –The key is that it is Web-accessible, not just browser-accessible. Another way of looking at a.NET web service is that it is a unit of managed code, typically installed under IIS, that can be remotely invoked using HTTP. A Web service is language agnostic. –All you care about is invoking the service with the input parameters formatted correctly, and parsing the output (if any).

Web Services Architecture Windows client Browser client Other client Web Server (IIS) Request Handler Web Service SOAP

Anatomy of a Web Service In.NET, a web service is implemented by one or more assemblies, just like any other library. In addition, some additional infrastructure is needed: –A wire protocol – used to transmit your service request and receive a response. (i.e. HTTP/GET, HTTP/POST or SOAP). –A description service – so clients can programmatically access and examine the interface contract. –A discovery service – so clients can programmatically discover the existence of web services.

Let's Look at Converting this Simple Code into a Web Service using System; class Hello { public string HelloMessage() { return ("Hello.NET Web Service"): }

The.asmx File using System; using System.Web.Services; class Hello:System.Web.Services.WebService { [WebMethod] public string HelloMessage() { return ("Hello.NET Web Service"); }

Let's Try It ! Save the.asmx file in the inetpub/wwwroot directory Access the web service by specifying the.asmx file in the URL (i.e. Invoking the web service this way automatically generates a web page that specifies the message format, and gives you a convenient invocation button for simple parameters. (i.e. it only supports a GET) Notice that the response is wrapped in XML

Web Service Directive Required for all web services Directive Name  WebService Variable number of attribute/value pairs –Language (C#, VB, JS, VJ#,...) C# is default –Class (required, class in either the.asmx or code- behind file, the code-behind file must be compliled and stored in the./bin subdirectory)

WebMethod Attribute class Hello:System.Web.Services.WebService { [WebMethod] public string HelloMessage() the Method must be public the WebMethod attribute has a number of properties

WebMethod Attribute Properties [WebMethod(property="value"...)] BufferResponse Property CacheDuration Property Description Property EnableSession MessageName TransactionOption

WebService Attribute Optional Provides additional information to be added to the Web Service Properties: –Description Property –Name Property –Namespace Property

Discovery File Provides a way for developers to find out about the methods exposed by the web service. Written in WSDL (Web Service Description Language)

Creating a Discovery File In a command window: disco.exe /out: Creates three output files –.disco file –.WSDL file –results.discomap file

Sample.disco File <discovery xmlns:xsd=" xmlns:xsi=" xmlns="

WSDL (Web Services Description Language) The XML Web services infrastructure is founded on communication via XML-based messages that comply with a published service description. The service description is an XML document written in an XML grammar called WSDL (Web Services Description Language) that defines the format of messages the XML Web service understands. The service description serves as an agreement that defines the behavior of an XML Web service and instructs potential clients in how to interact with it. The service description also specifies what the service consumer can expect to happen when a properly formatted message is submitted to the XML Web service.

WSDL File Document Elements A Web Service is described with a WSDL File. The following elements are involved in a WSDL document. –definitions – root element of a WSDL document. –types – optional element can be used to define the data types used to describe the messages exchanged by this service. –message – describes the messages exchanged by this service. Elements that represent the request and response, one per protocol (SOAP, HTTP GET and HTTP POST). –portType – defines a set of abstract operations (i.e. a single round-trip query and response), giving it a name. –binding – connects an abstract message to its message and transport (i.e. SOAP, HTTP GET, HTTP POST). Generally one binding element per transport. –service – maps each portType to its binding, associates a port and binding to a location (URL) where the service can be reached. –documentation – contains additional human readable information about the service. –import – allows a WSDL document to include the contents of another.

WSDL in Visual Studio.NET In Visual Studio.NET, for most part, you can ignore the details of the WSDL file and concentrate on implementing the service.

WSDL Specification

Web Service Deployment.asmx File (and.disco File) must reside in a virtual directory exposed by IIS so that they are accessible to a browser on the Internet. Directory structure is the same as for a.NET Web Form application with the code-behind file, web.config file (if it exists),./bin/WebServiceName.dll, etc.)

Let’s write a Web Service with Visual Studio.NET

Let’s write a web service with Visual Studio.NET Create a new project of type “ASP.NET Web Service” Notice that the project automatically creates a new virtual directory under IIS. (You may specify an existing virtual directory if you want.) A number of files are created, but the important ones are: –The.asmx file –The.asmx.cs file –The web.config file

The.asmx file The.asmx file contains the WebService processing directive and serves as the addressable entry point for the XML Web service.

The.asmx.cs file The.asmx.cs class file is a hidden, dependent file of the web service. It contains the code-behind class for the XML Web service. When viewing the Code View (F7) of the web service, you see the contents of this file.

The.asmx.cs file public class Service1 : System.Web.Services.WebService {... // uncomment the Hello web service [WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod] public string PersonalHello(string name) { return "Hello "+name; }

Other files The Web.config file –An XML-based file that contains configuration information for ASP.NET resources The.vsdisco file –An XML-based file used by ASP.NET's dynamic XML Web service discovery process, which uses this file to identify searchable paths on the Web server.

Testing your web service If you run your web service in Visual Studio.NET, it brings up a browser window and navigates to the.asmx page. This page contains all the web methods supported by the service. You also get a link to browse the WSDL service description file. Clicking on the method itself brings up a page which shows the various request and response formats. If the web method has simple parameters, a test harness allows you to invoke and debug the service.

Go To Browser Example

Web Service Client

Creating a Web Service Client Create a ASP.NET Web Application In the Solution Explorer, right click References and select Add Web Reference (You can rename the web reference here if you wish). Select the desired Web Service or enter following url... Visual Studio.NET queries the service and the WSDL file and creates a proxy object for you. You can now instantiate and use objects of the service class as if they were in a local assembly.

Adding a Web reference

Creating a Web Service Client Create a few labels, a textbox, and a couple of buttons Using the following code examples: –Add the using statement –Add the buttonclick code for each button –Remember: Instantiate the web service object Use the web service object to execute the method

Client Code Button1 using HelloClient.localhost;  Add a using statement private void Button1_Click(object sender, System.EventArgs e) { Service1 obj = new Service1();  Instantiate the service object Label3.Text = obj.HelloWorld();  Execute the method. }

Client Code Button2 private void Button2_Click(object sender, System.EventArgs e) { if (TextBox1.Text == "") { Label3.Text = "How about a name first!"; } else { Service1 obj = new Service1(); Label3.Text = obj.PersonalHello(TextBox1.Text); }

Class Exercise

Using Visual Studio create both a Hello Web Service and then a HelloClient which accesses the Hello Web Service.

Project Teams Homework Assignment

Final Homework / Project See Project Description on web. Work in teams or two or three. Complete work by end of class on Monday (or no later than Friday, the classroom should be available on Thursday). Be sure to capture and publish your learnings.