Developing Web Services and Web Applications with C - PowerPoint PPT Presentation

1 / 51
About This Presentation
Title:

Developing Web Services and Web Applications with C

Description:

Introduction to the C# language - ver CSharp.ppt. Introduction to ... Executa um dado comando com par metros (insert, delete ou update) para todas as linhas num ... – PowerPoint PPT presentation

Number of Views:396
Avg rating:3.0/5.0
Slides: 52
Provided by: grad159
Category:

less

Transcript and Presenter's Notes

Title: Developing Web Services and Web Applications with C


1
Developing Web Services and Web Applications with
C and Visual Studio.Net
  • Laboratório de Engenharia de Software
  • João Pascoal Faria
  • Outubro de 2006

2
Contents
  • Introduction to the .Net Framework ver
    CSharp.ppt
  • Introduction to the C language - ver CSharp.ppt
  • Introduction to Web Services
  • Creating a Web Service in Visual Studio .Net
  • Creating a Web Application that consumes a Web
    Service in Visual Studio .Net
  • Data access with ADO.Net

3
Introduction to Web Services
4
Defining Web Services
  • A web service is a chunk of functionality that
    can be accessed using web technology
  • Across an intranet or the Internet
  • Usually
  • Whats accessed is a method in a language such as
    Java or Visual Basic.NET
  • The web technology used is the Simple Object
    Access Protocol (SOAP) carried over HTTP
  • Both the .NET and Java camps have endorsed web
    services

5
Key Web Services Technologies
  • Web Services Description Language (WSDL)
  • An IDL for web services
  • Simple Object Access Protocol (SOAP)
  • An XML-based protocol for web services
  • Universal Description, Discovery, and Integration
    (UDDI)
  • A directory service for web services

6
Illustrating Web Services Technologies
UDDI Registry
Internet
UDDI Registry
Application
Application
Application
WSDL Interface
7
XML Web Services Protocol Stack
Internet Protocols
Directory of services UDDI
Service discovery DISCO
Service descriptions WSDL
Service interactions SOAP
Universal type system XSD
Universal data format XML
Ubiquitous communication Internet
8
Applying Web Services (1)
  • Connecting clients to Internet applications
  • One example is Microsofts .NET My Services
  • B2B integration on the Internet
  • The next generation of EDI
  • Enterprise application integration (EAI) on
    intranets
  • A standard approach to connecting all applications

9
Applying Web Services (2)
Internet
10
Describing Web Services WSDL
  • Created by Microsoft and IBM
  • Handed to the World Wide Web Consortium (W3C)
  • Endorsed by everybody
  • Microsoft, IBM, Sun, Oracle, BEA, more

11
Accessing Web Services SOAP
  • The Simple Object Access Protocol (SOAP) allows
    invoking operations
  • SOAP defines an XML-based format for parameters
  • SOAP requests/responses can ride on
  • HTTP
  • The most common case today
  • SMTP or MSMQ
  • For loosely-coupled interactions
  • Other protocols

12
What SOAP Provides
  • Industry agreement
  • Its endorsed by Microsoft, IBM, Sun, Oracle,
    BEA, Iona, and others
  • Object model independence
  • SOAP isnt tied to any operating system,
    programming language, or object model
  • Support for diverse protocols
  • Synchronous and asynchronous

13
Illustrating A SOAP Message
Envelope
Headers
Body
Method
Parameters
14
An Example SOAP Request (1)
  • POST /AccountAccess HTTP/1.1
  • Host www.qwickbank.com
  • Content-Type text/xml charsetutf-8
  • Content-Length 305
  • SOAPAction
  • ltSOAP-ENVEnvelope
  • xmlnsSOAP-ENV
  • "http//schemas.xmlsoap.org/soap/envelope/"
  • SOAP-ENVencodingStyle
  • "http//schemas.xmlsoap.org/soap/encoding/"gt

15
An Example SOAP Request (2)
  • ltSOAP-ENVBodygt
  • ltmGetBalance
  • xmlnsm"http//www.qwickbank.com/bank"gt
  • ltAccountgt729-1269-4785lt/Accountgt
  • lt/mGetBalancegt
  • lt/SOAP-ENVBody gt
  • lt/SOAP-ENVEnvelopegt

16
An Example SOAP Response (1)
  • HTTP/1.1 200 OK
  • Content-Type text/xml charset"utf-8"
  • Content-Length 304
  • ltSOAP-ENVEnvelope
  • xmlnsSOAP-ENV
  • "http//schemas.xmlsoap.org/soap/envelope/"
  • SOAP-ENVencodingStyle
  • "http//schemas.xmlsoap.org/soap/encoding/"gt

17
An Example SOAP Response (2)
  • ltSOAP-ENVBodygt
  • ltmGetBalanceResponse
  • xmlnsm"http//www.qwickbank.com/bank"gt
  • ltBalancegt3,822.55lt/Balancegt
  • lt/mGetBalanceResponsegt
  • lt/SOAP-ENVBody gt
  • lt/SOAP-ENVEnvelopegt

18
Discovering Web Services UDDI
  • Universal Description, Discovery, and Integration
    (UDDI) provides a specialized directory service
    for discovering compatible web services
  • It uses XML
  • Its endorsed by Microsoft, IBM, Ariba, Oracle,
    Sun, BEA, and more
  • An organization can create an XML-defined
    business registration
  • Which can contain information about various
    available web services

19
Illustrating A UDDI Business Registration
20
Creating a Web Service in Visual Studio .Net
21
ASP.NET
  • Active Server Pages for the .Net Platform
  • Allows creating two kinds of applications
  • Browser applications
  • Rely on .aspx pages
  • Web services applications
  • Rely on .asmx pages

22
Illustrating a Web Services Application
IIS
class X WebMethod public int Method1()

SOAP
app.asmx
ADO.NET
Common Language Runtime
DBMS
23
Exposing Web Services An Example .asmx Page
  • lt_at_ WebService Language"c" Class"Compute" gt
  • using System.Web.Services
  • public class Compute
  • WebMethod public int Factorial(int f)
  • int i
  • int result 1
  • for (i2 iltf i)
  • result result i
  • return result
  • WebMethod public double SquareRoot(double s)
  • return System.Math.Sqrt(s)

24
Controlling XML representation (1)Expose
public class OrderProcessor public void
SubmitOrder(PurchaseOrder order) ... public
class PurchaseOrder public string ShipTo
public string BillTo public string Comment
public Item Items public DateTime
OrderDate
public class OrderProcessor WebMethod
public void SubmitOrder(PurchaseOrder order)
... XmlRoot("Order", Namespace"urnacme.b2b
-schema.v1") public class PurchaseOrder
XmlElement("shipTo") public string ShipTo
XmlElement("billTo") public string BillTo
XmlElement("comment") public string Comment
XmlElement("items") public Item Items
XmlAttribute("date") public DateTime
OrderDate
25
Controlling XML representation (2)Consume
Order order new Order() order.ShipTo "Manuel
Costa" order.BillTo "Bill Gates" order.OrderDa
te DateTime.Today OrderProcessor.SubmitOrder(
order)
26
Controlling XML representation (3)SOAP request
message
lt?xml version"1.0" encoding"utf-8"?gt ltsoapEnvel
opegt ltsoapBodygt ltSubmitOrdergt ltOrder
date"20010703"gt ltshipTogtManuel
Costalt/shipTogt ltbillTogtBill
Gateslt/billTogt ltcommentgtOvernight
deliverylt/commentgt ltitemsgt
ltproductIdgt17748933lt/productIdgt
ltdescriptiongtDom Perignonlt/descriptiongt
lt/itemsgt lt/Ordergt lt/SubmitOrdergt
lt/soapBodygt lt/soapEnvelopegt
27
Creating a ASP.NET Web Service Project
28
Changing the Web Service Name
29
Accessing the Code Behind
30
Understanding the Code Behind
inheritance is optional (useful to create state
full web services)
31
Editing the Code Behind
attribute that tells that this method should be
exposed as a web service method
32
Understanding the .asmx page
In this case, everything is in the code behind
33
Build
34
Files Generated
35
Testing with a Browser
36
Viewing the dynamically generated WSDL (1)
37
Viewing the dynamically generated WSDL (2)
38
Creating a Web Application that consumes a Web
Service in Visual Studio .Net
39
Creating a ASP. NET Web Application
40
Adding a Reference to the Web Service
41
Viewing the Proxy Class Created Behind the Scenes
42
Designing the web page
43
Calling the web service
44
Running the client application
45
Data Access with ADO.Net
46
ADO.Net Architecture
SqlClient OleDb etc
47
Populating a DataSet from a DataAdapter
OleDb
OleDbConnection nwindConn new
OleDbConnection("ProviderSQLOLEDBData
Sourcelocalhost" "Integrated
SecuritySSPIInitial Catalognorthwind") OleDbCo
mmand selectCMD new OleDbCommand("SELECT
CustomerID, CompanyName FROM Customers",
nwindConn) OleDbDataAdapter custDA new
OleDbDataAdapter() custDA.SelectCommand
selectCMD DataSet custDS new DataSet()
custDA.Fill(custDS, "Customers")
SqlClient
SqlConnection nwindConn new SqlConnection("Data
SourcelocalhostIntegrated SecuritySSPIInitial
Catalognorthwind") SqlCommand selectCMD new
SqlCommand("SELECT CustomerID, CompanyName FROM
Customers", nwindConn) SqlDataAdapter custDA
new SqlDataAdapter() custDA.SelectCommand
selectCMD nwindConn.Open() DataSet custDS
new DataSet() custDA.Fill(custDS, "Customers")
nwindConn.Close()
48
Inserting, updating or deleting rows using a
DataTable and a SqlCommand with parameters
// Executa um dado comando com parâmetros
(insert, delete ou update) para todas as linhas
num // dataTable, preenchendo parâmetros com
valores lidos da mesma e devolve nº linhas
afectadas. private int ExecuteNonQuery(System.Data
.DataTable dt, System.Data.SqlClient.SqlCommand
sqlCommand) int rowsAffected 0 try
sqlCommand.Connection.Open() foreach(System
.Data.DataRow row in dt.Rows)
foreach(System.Data.SqlClient.SqlParameter
param in sqlCommand.Parameters) if
(row.IsNull(param.SourceColumn))
param.Value System.DBNull.Value
else param.Value rowparam.SourceColum
n rowsAffected sqlCommand.ExecuteNonQ
uery() sqlCommand.Connection.Close() c
atch(System.Exception e) ExceptionManager.Publ
ish(e) throw return rowsAffected
49
Saving changes to a DataTable
// Propaga alterações (update, delete, insert)
num dataTable para a BD usando um dataAdapter //
já configurado public virtual void
SaveChanges(System.Data.SqlClient.SqlDataAdapter
sqlDataAdapter, System.Data.DataTable
dt) try sqlDataAdapter.Update(dt) cat
ch(System.Exception e) ExceptionManager.Publi
sh(e) throw
50
Creating DataAdpaters with Visual Studio.Net
  • Just drag and drop a table to the application

51
Binding DataTables to Data Grids
  • Just change a property in the data grid
Write a Comment
User Comments (0)
About PowerShow.com