• No results found

Web Services in.net (1)

N/A
N/A
Protected

Academic year: 2021

Share "Web Services in.net (1)"

Copied!
28
0
0

Loading.... (view fulltext now)

Full text

(1)

Web Services in .NET (1)

These slides are meant to be for teaching purposes only and only for the students that are registered in CSE4413 and should not be published as a

(2)

What is a Web Service?

• A Web Service (WS) is a class (or many

classes) that resides in a computer and it is

accessible from another computer, in the sense

that clients can call methods of this class

remotely.

• In .NET, any method of a class can be equipped

to be accessed remotely. All it needs is to

associate the attribute

[WebMethod]

with that

method.

(3)

Web Services vs “Local” Services …

Access is done via local

system calls (managed by the

local operating system). Access is done via “remote

system calls” managed by

HTTP and SOAP (Simple

Object Access Protocol) a protocol that allows calling remote methods).

Class produces DLL file which is stored in local computer, and it is accessed from classes

residing in same computer. Class produces DLL file which is

stored in local computer, and it is accessed from classes

residing in some other computer

Local service

Web service

(4)

Web Services vs “Local” Services …/

We learn about local methods via the API.

We learn about Web Services

via UDDI (Universal Description Discovery and Integration) and

DISCO. [ in practice, however, so far,

API may be written in XML. WSDL is written in XML.

Documentation for a local

method is provided via a local API (Application Programming

Interface).

Documentation for a web method is provided via WSDL

(Web Service Description Language).

Local service

Web service

(5)

Evolution of the internet and the WWW (0)

Generation 0

FTP, e-mail

(6)

Evolution of the web (1)

Generation 1

Static HTML

(7)

Evolution of the web (2)

Generation 2

Web Applications

(8)

Evolution of the web (3)

HTML, XML

HTML, XML

Generation 3 (under construction)

(9)

Evolution of the web (4)

empID

HTML, XML

HTML, XML, RDF

Generation 4 (under contemplation)

Semantic Web

Emp-id

Check and be able to realize that empID

and Emp-id mean the same thing.

(10)

Benefits of Web Services …

• May facilitate significant boost for developing

distributed applications.

• Use standard (SOAP) for message exchange.

• Use standard for interface description (WSDL),

in XML.

• Independent of programming languages and

operating systems.

• Utilize existing Internet protocols (HTTP usually,

but also SMTP and FTP).

(11)

Benefits of Web Services …/

• Web Services allow you to interconnect:

– Different companies

– Many/any devices

– Applications

– Different clients

• Not just browsers

• Distribution and integration of application logic

• Enable the

programmable

Web

– Not just the purely

interactive

Web

(12)

Comparison of various distributed (Web Services and

ancestors) technologies

SOAP ORB/CDR .NET object serialization Java object serialization Message exchange format HTTP, HTTPS, SMTP, FTP GIOP/IIOP binary or OAP RMI-IIOP Transport protocol XML data IDL-specified objects .NET objects Java objects (binary) Data exchange format WSDL (XML-based) CORBA IDL .NET Interfaces Java Interfaces Interface definition independent independent .NET languages (C#, VB.NET, ..) Java Programming language

Web

services

CORBA

.NET

Remoting

Java RMI

(13)

Web services related .NET

namespaces

• System.Web.Services

– for developing Web services (e.g.: WebService, WebMethod)

• System.Web.Services.Configuration

– for extending SOAP

• System.Web.Services.Description

– for creating and manipulating WSDL descriptions

• System.Web.Services.Discovery

– for using DISCO

• System.Web.Services.Protocols

– for implementation of communication protocols (e.g.

SOAP-HTTP)

(14)
(15)

A .NET web service has a .asmx file associated with it. This is the equivalent of

the .aspx file of ASP.net applications.

(16)

Running …

The operation (method) exposed by this web service

The URL of the web service

The WSDL (web service description

(17)

The result of invoking method

“Hello World”

(18)

The code:

Service1.asmx.cs

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Services; namespace WebService1 { /// <summary>

/// Summary description for Service1.

/// </summary>

public class Service1 : System.Web.Services.WebService {

public Service1() {

//CODEGEN: This call is required by the ASP.NET Web Services Designer

InitializeComponent(); }

#region Component Designer generated code

Class Service1 is our Web Service. (Subclass of

(19)

…/

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent() {

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing ) {

if(disposing && components != null) { components.Dispose(); } base.Dispose(disposing); } #endregion

// WEB SERVICE EXAMPLE

// The HelloWorld() example service returns the string Hello World

[WebMethod]

public string HelloWorld() {

return "Hello World";

The web service method HelloWord() C# attribute, that makes this method exposed as

(20)

How to use the HelloWorld web service

• Any .NET application

– Console application

– Windows application

– Web Application

(21)

A console application that uses the

HelloWorld Web Service

Output string “Hello World” comes from the returned value

of method HelloWorld() that had been invoked.

(22)

The code

1. Create a console application, and

(23)

3. Find the Web Service to use. In this case,

select from the local machine.

(24)

4. Once the service is found, type the name you like to use

to reference it (HelloWorldWebService, in this example).

(25)

5. The web service is made available for use in

ConsoleApplication1.

(26)

The method HelloWorld() of this web service.

Class1 is the console application that uses (consumes) the web service.

(27)

The consumer class: Class1

(28)

Class1 is the consumer, i.e., contains the code

that uses the web service.

using System;

namespace ConsoleApplication1 {

class Class1 {

private HelloWorldWebService.Service1 myWS;

[STAThread]

static void Main(string[] args) {

new Class1().go(); }

public void go() {

myWS = new HelloWorldWebService.Service1();

Console.WriteLine( myWS.HelloWorld() ); }

Declare a WebService

References

Related documents

Schwartz Outcome Scale-10 (SOS-10) [ 24 ] was chosen as a second convergent validity check as it is an- other brief self-report scale with similar aims to the CORE-OM and has a

In short-horizon sessions, where investors exit the market by receiving the price (not dividends), prices levels and paths become indeterminate and lose dividend anchors;

Advertising - Mass Communication, Communication, Computer Science , Economics, Environmental Public Health, Graphic Design, Journalism, Liberal Studies, Math, Public Relations -

The study provides important implications for invest- ment managers as well as researchers. The results of our study seem to suggest that 1) Cross sectional variance helps in

Milla Holm (b. 2000) entered the cello class of Taru Aarnio at the East Helsinki Music Institute when she was six and in 2012 transferred to the junior Sibelius Academy a pupil

[r]

To better understand tracking tools, Leasing Professionals should understand how a prospective resident searches an online apartment publication site.. While some sites differ,

By examining the moral discourses of love within the drama in conjunction with the personal experiences of my informants (echoing the ways my own informants spoke of their