asp.net web services. a unit of managed code installed under iis that can be remotely invoked using...

20
ASP.NET ASP.NET Web Services Web Services

Upload: sherilyn-turner

Post on 18-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

ASP.NET ASP.NET

Web ServicesWeb Services

Page 2: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

Web ServicesWeb Services

A unit of managed code installed under IIS A unit of managed code installed under IIS that can be remotely invoked using HTTP.that can be remotely invoked using HTTP.

Page 3: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

Similar TechnologiesSimilar Technologies

DCOMDCOM CORBACORBA EJB (Enterprise Java Beans)EJB (Enterprise Java Beans)

All are tied to a specific language or a All are tied to a specific language or a proprietary protocol.proprietary protocol.

Page 4: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

Introducing Web ServicesIntroducing Web Services

Language Agnostic.Language Agnostic. Can be called by any program that can Can be called by any program that can

parse XML and use HTTP.parse XML and use HTTP. Can be called from Web Forms as well as Can be called from Web Forms as well as

Windows Forms.Windows Forms.

Page 5: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

Supporting TechnologiesSupporting Technologies

Web Service Description Language (WSDL)Web Service Description Language (WSDL) A wire protocol (HTTP GET, HTTP POST, or SOAP)A wire protocol (HTTP GET, HTTP POST, or SOAP) A discovery Service (*.disco files)A discovery Service (*.disco files) ProxiesProxies IISIIS

Page 6: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

Building a Simple Web ServiceBuilding a Simple Web Service

Select C# Projects->ASP.NET Web Service.Select C# Projects->ASP.NET Web Service. Automatically creates a virtual directory Automatically creates a virtual directory

under IIS.under IIS. Can test from within the program without Can test from within the program without

using a client.using a client.

Page 7: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

WebService Base ClassWebService Base Class

Not required to derive from this class, can inherit Not required to derive from this class, can inherit directly from object.directly from object.

Adds functionality such that a web service can Adds functionality such that a web service can interact with the same types used by the ASP.NET interact with the same types used by the ASP.NET object model:object model:– Application ObjectApplication Object– Context ObjectContext Object– Server ObjectServer Object– Session ObjectSession Object– User ObjectUser Object

Page 8: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

WSDLWSDL

WWeb eb SService ervice DDescription escription LLanguageanguage Contract between the client and the web Contract between the client and the web

service, that defines the interactionservice, that defines the interaction– Function names.Function names.– Parameters and their types.Parameters and their types.– Syntax of various wire protocols.Syntax of various wire protocols.

System.Web.Services.Description contains System.Web.Services.Description contains types that allow you to programmatically types that allow you to programmatically manipulate the WSDL.manipulate the WSDL.

Page 9: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

SOAPSOAP

Simple Object Access ProtocolSimple Object Access Protocol XML BasedXML Based TypesTypes

– ADO.NET DataSetsADO.NET DataSets– Complex ArraysComplex Arrays– Custom TypesCustom Types

Binding:Binding:</binding></binding> <service name="<service name="HPSIClaimServicesHPSIClaimServices">"> <port name="<port name="HPSIClaimServicesSoapHPSIClaimServicesSoap" binding="" binding="s0:HPSIClaimServicesSoaps0:HPSIClaimServicesSoap">">

   <soap:address location="<soap:address location="http://localhost/HPSIClaimServices/HPSIClaimServices.asmxhttp://localhost/HPSIClaimServices/HPSIClaimServices.asmx" /> " /> </port></port> </service></service>

Page 10: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

ProxiesProxies

Creates a class that contains the interface for your Creates a class that contains the interface for your web serviceweb service

Using wsdl.exeUsing wsdl.exeC:\wsdl.exe out:c:\testproxy.csC:\wsdl.exe out:c:\testproxy.cshttp://localhost/testwebservice/text.asmx?wsdlhttp://localhost/testwebservice/text.asmx?wsdl

Using Visual Studio .NETUsing Visual Studio .NET– Add Web ReferenceAdd Web Reference

Page 11: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

ProxiesProxies

Adds Asynchronous and Synchronous Adds Asynchronous and Synchronous versions of each exposed Web Methodversions of each exposed Web Method

Looks and feels like the Web Service is a Looks and feels like the Web Service is a class in the client applicationclass in the client application

Page 12: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

AdvancedAdvanced

Serializing Custom TypesSerializing Custom Types Using Session to maintain information from Using Session to maintain information from

previous callsprevious calls Connecting to a Database Connecting to a Database

Page 13: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

Serializing Custom TypesSerializing Custom Typesusing System;using System;using System.Xml.Serialization;using System.Xml.Serialization;

namespace CarsWebServicenamespace CarsWebService{{ //Tells the serializer to generate the proper XML tags for a car//Tells the serializer to generate the proper XML tags for a car typetype [XmlInclude(typeof(Car))] [XmlInclude(typeof(Car))] public class Carpublic class Car {{ public string name;public string name; public int maxSpeed;public int maxSpeed; public Car(){}public Car(){} public Car(string n, int s)public Car(string n, int s) {{ name = n;name = n; maxSpeed = s;maxSpeed = s; }} }}}}

//The XML Serializer will only serialize public members or properties that expose //The XML Serializer will only serialize public members or properties that expose those membersthose members

Page 14: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

Session StateSession Statenamespace TestServicenamespace TestService{{

public class TestService1 : public class TestService1 : System.Web.WebServiceSystem.Web.WebService{{

public TestService1()public TestService1(){{

InitializeComponent();InitializeComponent();Session.Add(“TestDataSet”, null);Session.Add(“TestDataSet”, null);

}}

[WebMethod][WebMethod]public void TestMethod(DataSet ds)public void TestMethod(DataSet ds){{

Session[“TestDataSet”] = ds;Session[“TestDataSet”] = ds;}}

}}}}

Page 15: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

Database ConnectionsDatabase Connections

Allows for Database client software to reside on one Allows for Database client software to reside on one machine.machine.

Allows for one consistent interface to the database.Allows for one consistent interface to the database.

Allows the business rules to be separate from the clientAllows the business rules to be separate from the client

Page 16: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

Discovery Service ProtocolDiscovery Service Protocol Describes each Web Service in a given virtual directory.Describes each Web Service in a given virtual directory. .disco file is part of the client project.disco file is part of the client project C:\disco <URL for .disco file>C:\disco <URL for .disco file>

<?xml version="1.0" encoding="utf-8"?><discovery xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.xmlsoap.org/disco/"> <contractRef ref="http://161.28.113.202/HPSIBuildRunServices/BuildRunService.asmx?wsdl" docRef="http://161.28.113.202/HPSIBuildRunServices/BuildRunService.asmx" xmlns="http://schemas.xmlsoap.org/disco/scl/" /> <soap address="http://161.28.113.202/HPSIBuildRunServices/BuildRunService.asmx" xmlns:q1="hpsiserver.hpsionline.com" binding="q1:BuildRunServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" /></discovery>

Page 17: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

Distributing over a networkDistributing over a network

DatabaseWeb

Service

WebForm

WindowsForm

Page 18: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

Creating a Web Service ProjectCreating a Web Service Project

Choose ASP.NET Web ServiceChoose ASP.NET Web Service The project is created in C:\Inetpub\The project is created in C:\Inetpub\

wwwroot\projectnamewwwroot\projectname The web service file is .asmxThe web service file is .asmx

– Code behind is in .asmx.cs fileCode behind is in .asmx.cs file

IIS must be installedIIS must be installed

Page 19: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

Using a Web ServiceUsing a Web Service

Add a web referenceAdd a web reference– The proxy is hidden in the Web Reference The proxy is hidden in the Web Reference

Create an instance of the proxy classCreate an instance of the proxy class Use the proxy instance as you would a Use the proxy instance as you would a

normal class instancenormal class instance

Page 20: ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP

ConclusionConclusion

Web Services are cool!Web Services are cool! Can be used to allow dissimilar systems to Can be used to allow dissimilar systems to

communicatecommunicate Easy to implementEasy to implement Easy to learn how to useEasy to learn how to use Fairly SlowFairly Slow