Web Services
February 14th, 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 Network Web Application
Service code
client
Web Service Technology Stack
shopping web service?
Discovery Web Service
WSDL URIs UDDI
Client
Web Service
Description WSDL
WSDL
SOAP pkg request
Packaging Proxy SOAP pkg response
Transport
Network
Step1. Write Web Service Method
shopping web service?
Discovery Web Service
WSDL URIs UDDI
Client
Web Service
Description WSDL
WSDL
SOAP pkg request
Packaging Proxy SOAP pkg response
Transport
Network
Step2. Describe Web Service using WSDL
shopping web service?
Discovery Web Service
WSDL URIs UDDI
Client
Web Service
Description WSDL
WSDL
SOAP pkg request
Packaging Proxy SOAP pkg response
Transport
Network
Step3. Write Proxy to Access Web Service
shopping web service?
Discovery Web Service
WSDL URIs UDDI
Client
Web Service
Description WSDL
WSDL
SOAP pkg request
Packaging Proxy SOAP pkg response
Transport
Network
Step4. Write Client to Invoke Proxy
shopping web service?
Discovery Web Service
WSDL URIs UDDI
Client
Web Service
Description WSDL
WSDL
SOAP pkg request
Packaging Proxy SOAP pkg response
Transport
Network
Step1. Create a Web Service
• 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)
{…}
Creating a Web Service with .Net
Creating a Web Service with .Net
Creating a Web Service with .Net
Creating a Web Service with .Net
Creating a Web Service with .Net
[WebMethod]
public string HelloWorld(string name)
{
return "Hello " + name;
}
Compile and View Your Web Service
Compile and View Your Web Service
Compile and View Your Web Service
Step2. Describe Web Service using WSDL
• 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>
WSDL Generated by .NET
WSDL Generated by .NET
SOAP (Simple Object Access Protocol)
• SOAP Messages
• Using SOAP as RPC (Remote Procedure
Call) Messages
Request message
SOAP client SOAP server
Response message
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
Create a Proxy (Web Reference) with .Net
Create a Proxy (Web Reference) with .Net
Create a Proxy (Web Reference) with .Net
Create a Proxy (Web Reference) with .Net
Read Code for Proxies
Read Code for Proxies
Read Code for Proxies
Read Code for Proxies
public class helloWorld : System.Web.Services.
Protocols.SoapHttpClientProtocol
{
public helloWorld() {
this.Url = "http://iinetsrv.csepclab.cs.washington
.edu/cse444wi03/TAtest/WebService/helloWorld.
asmx";
}
…
Step4. Write a Client to Invoke Proxy
Step4. Write a Client to Invoke Proxy
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);
}
Step4. Write a Client to Invoke Proxy
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