36
Web Services February 14 th , 2003

Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Embed Size (px)

Citation preview

Page 1: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Web Services

February 14th, 2003

Page 2: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Outline

• Overview of web services

• Create a web service with MS .Net

• Requirements for project Phase II

Page 3: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

What is a Web Service• A web service is a network accessible interface to

application functionality, built using standard Internet technologies.

• Clients of web services do NOT need to know how it is implemented.

Application

client

Application

codeNetwork Web

Service

Page 4: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Web Service Technology Stack

DiscoveryDiscovery

DescriptionDescription

PackagingPackaging

TransportTransport

NetworkNetwork

shopping web service?

WSDL URIsWeb ServiceClient

Web Service

UDDI

Proxy

WSDL

SOAP pkg requestWSDL

SOAP pkg response

Page 5: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Step1. Write Web Service Method

DiscoveryDiscovery

DescriptionDescription

PackagingPackaging

TransportTransport

NetworkNetwork

shopping web service?

WSDL URIsWeb ServiceClient

Web Service

UDDI

Proxy

WSDL

SOAP pkg requestWSDL

SOAP pkg response

Page 6: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Step2. Describe Web Service using WSDL

DiscoveryDiscovery

DescriptionDescription

PackagingPackaging

TransportTransport

NetworkNetwork

shopping web service?

WSDL URIsWeb ServiceClient

Web Service

UDDI

Proxy

WSDL

SOAP pkg requestWSDL

SOAP pkg response

Page 7: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Step3. Write Proxy to Access Web Service

DiscoveryDiscovery

DescriptionDescription

PackagingPackaging

TransportTransport

NetworkNetwork

shopping web service?

WSDL URIsWeb ServiceClient

Web Service

UDDI

Proxy

WSDL

SOAP pkg requestWSDL

SOAP pkg response

Page 8: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Step4. Write Client to Invoke Proxy

DiscoveryDiscovery

DescriptionDescription

PackagingPackaging

TransportTransport

NetworkNetwork

shopping web service?

WSDL URIsWeb ServiceClient

Web Service

UDDI

Proxy

WSDL

SOAP pkg requestWSDL

SOAP pkg response

Page 9: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

• Functionality is implemented in .asmx.vb or .asmx.cs files.– <%@WebService Language=“C#” Class=“helloWorld” %>

• Use System.Web.Services Namespace– Using System.Web.Services

• Inherit your own class from WebService Base Class– public class helloWorld : System.Web.Services.WebService

• Declare the WebMethod Attribute– [WebMethod]

public string HelloWorld(string name){…}

Step1. Create a Web Service

Page 10: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Creating a Web Service with .Net

Page 11: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Creating a Web Service with .Net

Page 12: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Creating a Web Service with .Net

Page 13: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Creating a Web Service with .Net

Page 14: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

[WebMethod]

public string HelloWorld(string name)

{

return "Hello " + name;

}

Creating a Web Service with .Net

Page 15: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Compile and View Your Web Service

Page 16: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Compile and View Your Web Service

Page 17: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Compile and View Your Web Service

Page 18: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

• WSDL (Web Services Description Language)• Describes 3 ways to access web service: GET, POST, SOAP• Element:

– <types>: XML schema for input/output– <message>:

• HelloWorldSoapIn, …SoapOut, …HttpGetIn, …HttpGetOut, …HttpPostIn, …HttpPostOut

– <porttype>• helloWorldSoap, …HttpGet, …HttpPost

– <binding>• s0:helloWorldSoap, s0:…HttpGet, s0:…HttpPost

– <service name = “helloWorld”><port name = “…Soap” binding = “s0:…Soap”>

<soap:address location = “http://…”/></port></service>

Step2. Describe Web Service using WSDL

Page 19: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

WSDL Generated by .NET

Page 20: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

WSDL Generated by .NET

Page 21: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

SOAP (Simple Object Access Protocol)

• SOAP Messages

• Using SOAP as RPC (Remote Procedure Call) Messages

SOAP client SOAP serverRequest message

Response message

Page 22: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Step3. Write Proxy to Access Web Service

• In software, a proxy is the code that does work on behalf of other code. – For web service users, the proxy represents the

web service the users wish to call– For web service servers, the proxy makes

request on the behalf of the user

Page 23: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Create a Proxy (Web Reference) with .Net

Page 24: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Create a Proxy (Web Reference) with .Net

Page 25: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Create a Proxy (Web Reference) with .Net

Page 26: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Create a Proxy (Web Reference) with .Net

Page 27: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Read Code for Proxies

Page 28: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Read Code for Proxies

Page 29: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Read Code for Proxies

Page 30: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

public class helloWorld : System.Web.Services. Protocols.SoapHttpClientProtocol

{

public helloWorld() {

this.Url = "http://iinetsrv.csepclab.cs.washington .edu/cse444wi03/TAtest/WebService/helloWorld. asmx";

}

Read Code for Proxies

Page 31: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Step4. Write a Client to Invoke Proxy

Page 32: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Step4. Write a Client to Invoke Proxy

Page 33: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Step4. Write a Client to Invoke Proxy

private void invoke_Click(object sender, System.EventArgs e)

{

helloWorld myHello = new helloWorld();

string helloName = name.Text;

hello.Text = myHello.HelloWorld(helloName);

}

Page 34: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Step4. Write a Client to Invoke Proxy

Page 35: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II

Requirements for project Phase II

• Write your web services– Class name: [your_group_name]_webService.

For example, RBM_webService – 4 Methods: details on project info webpage

• Write a simple client for each web method– Input: text boxes (with default value)– Invoke button– Output: label

Page 36: Web Services February 14 th, 2003. Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II