Title: Web Services with ASP'NET
1(No Transcript)
2Web ?????? ? ASP.NET
???????????? ?? .NET Framework
http//www.nakov.com/dotnet/
??????? ?????
????????? ????????? ???????????????? ?? ???????
www.devbg.org
3?????????? ??????
- ?????? ???????? ?? .NET Framework
- ?????? ???????? ?? ????? C
- ?????? ???????? ?? ASP.NET
- ??????? ?????? ?? ?????? ? Visual Studio .NET
4??????????
- ???????????? ??????????
- ??????? ?? Web ??????
- ?????? ? Web ??????
- ???????????????? ?? Web ????????
- UDDI ?????????? ?? Web ??????
- ????????? ?? Web ?????? (DISCO)
- WSDL ???????? ?? ??????
- SOAP ?????? ?? ????????
- ?????????? ???? ?? Web ????????
5?????????? (2)
- ???????? ?? ?????????? ?? Web ??????
- .NET Enterprise ??????????
- Web ???????? ? ASP.NET
- ????????? ?? Web ??????
- ??????????? ?? Web ??????
- ?????????? ?? Web ??????. ?????????? ?? ??????
???? - Web ???????? ? VS.NET
6?????????? (3)
- ???????? ?? Web ???????? - WebService,
WebMethod - ??????????? ?? ??????
- ????????? ?? Web ??????
- ?????????? ?????????
- Web ?????? ? ?????? ? ?????
- ????????? ?? ?????
7???????????? ??????????
- ???????? ?????? ?????????? ?? ????????????
- ??????? ?? ?? ??????? ??????????? ??????????,
????? ?? ?????????????? - ?????? ?? ???????????? ??????????
- ????? "??????/??????"
- ????? "???????????? ??????"
- DCOM ?????? ?? ? Microsoft Windows
- CORBA ??????? ????????, ????? ??????
- Java RMI ?????? ?? ?? Java ????????????
- ????? "Web ??????"
8??????? ?? Web ??????
- ??????? "???????????? ?????? ?? ? ???????? ??
???????? ? ???????? - ????? ?????????? ????? ?????? ? ??????
- ????????? ??? ??????????? ??????????????
- ???????? ? ????????
- ????????? ????? (firewalls) ????? ???????????
????????????? - COM/DCOM ?? ???????? ???? ? Windows
- CORBA ?? ?????? ???? ????????
- Java RMI / EJB ?? ????????? ???? ? Java
- ????????? Web ??????
9????? ? ???????
- ? ??????? ???? ???????? ?
- ??????? ??????, ?????????? ?? ????????? ?? ??????
- ?????????? ??????? ????? ???????? ?? ???????
(?????????? ?? ??????) - ? ???? ?????????? ?????? ????????? ? ???????
????????? - ????? ?? ??????????
- ?????? ????????
- ??? ?????????????? ?? ???????? (????, ????? ??
?????????? ? ??.)
10Web-??????
- Web-???????? ????????? ???????? ?? ??????? ????
- ????????? ??????????, ???????? ?????????? ????
Web - ????? ?? ?????????? ??????-???????
- ???????? ???????, ???????? ????????? ????????? ?
????? ???????? - ????????? ???????? ????????? ?? ???????????
HTTP, XML ? SOAP - ???? ??????? ?????????? ?? ?? ?????? ???? ?????
WSDL - ????? ?? ????? ??????? ???? UDDI
11Web-??????
- Web-???????? ????????? ???????? ?? ??????? ????
- ??????? ?? ???????? ?? ?????? ?? SOAP ?????????
- ??????????? ???????? ????????????? ??????????
????? ????????? (???????? ?? ???????) - ?????????? ?? ????????????? ???????, ???????????
? ????? ?? ???????????? - ????????????-?????????? (loosely coupled)
- ?????-????????? ? ???????
12????????????????
- ???????????????? ?? Web ???????? ?? ?????? ??
???????? ?????????? - ?????????? (Directory)
- UDDI
- ????????? (Discovery)
- DISCO
- ???????? (Description)
- WSDL
- ?????? ?? ???????? (Wire Format)
- SOAP
- XML, XSD, HTTP
13?????????? ?? Web ??????
- ???????????? ?? Web ??????
- ?????????? ??????? ?? Web ??????
- ???????????? ?? ?? ?????????
- ???? ?? ?? ????? ?? ???????? ?????????
- ????????? UDDI ?????????
- UDDI (Universal Description, Discovery and
Integration) - ??????? ???????? ?? OASIS
- ???????????? Web ??????, ?????????? ??????????? ?
??????? ?? ?????? - ?????? ?? UDDI ??????????
- http//uddi.microsoft.com
14?????????? ??????
15????????? ?? Web ??????
- ??????????? ?? Web ??????
- ????????? ?? ?? ??????? ?????????? ?? Web ??????
?? ????? ?????? - ????????? ?? ?. ???. "discovery" ???????
(.disco) - DISCO (Discovery of Web Services)
- XML ??????? ????, ?????????? ?? Microsoft
- ?????? Web ???????? ?????? ??? WSDL ?????,
?????? ??? ?????? ?????? ? ?????? ???
???????????? ?? ???????? - ?????????? disco ?????? ???? ? ????????
?????????? ?? ???????? - ????. http//www.mysite.com/math/math.disco
16DISCO ??????? ??????
lt?xml version"1.0" encoding"utf-8"?gt ltdiscovery
xmlns"http//schemas.xmlsoap.org/disco/"gt
ltcontractRef ref"http//www.myserver.com/De
mo-5-Service-Types/TypesService.asmx?wsdl"
docRef"http//www.myserver.com/Demo-5-Service-Typ
es/TypesService.asmx" xmlns"http//schemas.
xmlsoap.org/disco/scl/" /gt ltsoap
address"http//www.myserver.com/Demo-5-Service-Ty
pes/TypesService.asmx" xmlnsq1"http//www.my
server.com/schemas/ Demo_5_Service_Types/"
binding"q1TypesServiceSoap"
xmlns"http//schemas.xmlsoap.org/disco/soap/"
/gt lt/discoverygt
17WSDL ???????? ?? ??????
- WSDL (Web Services Description Language)
- ?????? ?????????? ?? ?????? ?? ?????? Web ??????
- ??????? ?? ???????????? ??????
- ?????? ? ??????? ?????????
- ?????????? ?????? ?????
- XML ??????? ??????? ???????? ?? W3C
- ASP.NET Web ???????? ?????? ???? WSDL ???
????????? ? ????????? ?wsdl - http//localhost/MyService.asmx?wsdl
18WSDL ???????? ??????
lt?xml version"1.0" encoding"utf-8"?gt ltdefinition
s xmlnshttp"http//schemas.xmlsoap.org/wsdl/http
/" xmlnssoap"http//schemas.xmlsoap.org/wsdl/so
ap/" xmlnss"http//www.w3.org/2001/XMLSchema"
xmlnss0"http//www.devbg.org/ws/MathService"
xmlnssoapenc"http//schemas.xmlsoap.org/soap/enc
oding/" xmlnstm"http//microsoft.com/wsdl/mime/
textMatching/" xmlnsmime"http//schemas.xmlsoap
.org/wsdl/mime/" targetNamespace"http//www.devb
g.org/ws/MathService" xmlns"http//schemas.xmlso
ap.org/wsdl/"gt lttypesgt lt/typesgt ltmessage
name"AddSoapIn"gt lt/messagegt ltportType
name"MathServiceSoap"gt lt/portTypegt ltbinding
name"MathServiceSoap" gt lt/bindinggt ltservice
name"MathService"gt lt/servicegt lt/definitionsgt
19SOAP ?????? ?? ????????
- SOAP (Simple Object Access Protocol)
- ???????? XML ??????? ?????? ?? ?????? ??
????????? - ??????? ???????? ?? W3C
- ???? SOAP ????????? ?? ?????? ??
- SOAP ????? ?????? ????????? ?? ???????????
(?????????) - SOAP ???? ??????? ?????? ????????? (?????
??????????? ??? ????????? ??????) - ?????????? SOAP ??????????? ?? ???????? ??
???????? HTTP - ???? ????????? ?? ?????????? ???? firewall
20SOAP ?????? ??????
lt?xml version"1.0" encoding"utf-8"?gt ltsoapEnvel
ope xmlnsxsi"http//www.w3.org/2001/XMLSchema-
instance" xmlnsxsd"http//www.w3.org/2001/XMLS
chema" xmlnssoap"http//schemas.xmlsoap.org/so
ap/envelope/"gt ltsoapBodygt ltCalcDistance
xmlns"http//www.devbg.org/Calc"gt ltp1gt
ltxgt4lt/xgt ltygt5lt/ygt lt/p1gt
ltp2gt ltxgt7lt/xgt ltygt-3lt/ygt
lt/p2gt lt/CalcDistancegt lt/soapBodygt lt/soapEn
velopegt
21SOAP ??????? ??????
lt?xml version"1.0" encoding"utf-8"?gt ltsoapEnve
lope xmlnsxsi"http//www.w3.org/2001/XMLSchema
-instance" xmlnsxsd"http//www.w3.org/2001/XML
Schema" xmlnssoap"http//schemas.xmlsoap.org/s
oap/envelope/"gt ltsoapBodygt
ltCalcDistanceResponse xmlns"http//www.devb
g.org/Calc/"gt ltCalcDistanceResultgt
8,54400374531753 lt/CalcDistanceResultgt
lt/CalcDistanceResponsegt lt/soapBodygt lt/soapEnv
elopegt
22????????????????
???????? MSDN
23?????????? ???? ?? Web ????????
?????????
SOAP
?????????
WSDL
XSD
?????
XML
?????
HTTP
?????????
24HTTP, XML, XSD
- ???????? ?? ?????? ?? ?????????? ????? Web ??????
? Web ??????? - ???????? ?????? "??????-???????"
- ?? ???????? ?????????? ????? (stateless)
- ??????? ???????? ?? W3C
- XML
- ?????, ????????-??????? ???? ?? ?????????????
???????? ?? ?????????? - ??????? ???????? ?? W3C
- XSD
- ????? XML-??????? ???? ?? ???????? ???????????
(???????) ?? XML ????????? - ??????? ???????? ?? W3C
25???????? ?? ??????????
- ??????? ???????? ?? ???????? ?? Web ??????
- ?????? ??? ????????? ??????????
- ????? ?? ?? ?????????? ???????? ?? ?????????,
???????? ?? MS Office - ?????????? ?? ??????????
- ?????????????? ????? ??????????, ???????? ??
???????? ????????? ? ?? - ?????? ????? ????????? ?????????? ??? Enterprise
??????????
SOAP ??????
ADO .NET
Web ??????
Front End (??????)
Back End (???? ?????)
26Enterprise ??????????
- ????? ?? "Enterprise ????????????"?
- ??????????? ???????????? ??????????, ??????????
?? ??????? ?? ???????? ???????????? ??????? - ????????
- ??????????
- ????? ??????????
- ????????? ?? ???????
- Enterprise ? "buzzword" ??????? ????, ?? ?????
????? ?? ??????, ????? ?? ????????? ? ???? ?????
????????? ????? ????????
27.NET Enterprise ??????????
- ???????????? Enterprise ??????????? ? ?????????
28.NET Enterprise ??????????
- ???????? ? ??????????? ???????????
- ?????????????? ???? (Front End)
- ????????? ???????????????? ? ???????????
(????????????? ?????????) - Windows Forms ? ASP.NET Web ??????????
- ?????? ???? (Business Tier)
- ????????? ????????? ??????? ? ?????????? ???
??????? (?????? ????????) - ASP.NET Web ??????
- ???? ?? ??????? (Back End)
- ????????? ??????? ?? ?????????
- ???? ?? ????? (MS SQL Server, Oracle, DB2)
29Web ???????? ? ASP.NET
- ?????????? ?? ? ?????????????? System.Web.Services
- ????????????? ??????????? ? ?????????? ?? SOAP
????????? - ?????????? ????????????? ?? ???????? ?? XML ?
.NET ?????? ? ????????? - ??????????? ?????????? ?? WSDL ????????
- ??????????? ?????????? ?? C ?????? ??????? ??
WSDL ????????
30ASP.NET Web ?????? ???????????
- Web ???????? ?? ??????? ? IIS (Internet
Information Server) - ?????????? ?? ?? ASP.NET ???????? ??????
(aspnet_wp)
????????? ???
ASP.NET Web ?????? WebMethod public string
blah()
????????? (.NET / Java / PHP / Perl)
ISAPI ??????
ASP.NET ??????? ??????
IIS
Common Language Runtime
??
??????????? ??????? (Win2000, WinXP, Win2003)
31????????? ?? Web ??????
- ? .NET Framework ?? ????????? ?? Web ?????? ??
??????? .asmx ???? - ?????? ?? ????????? ???, ???????, ?? ?????? ? Web
?????? - ????????? ?? ?????? System.Web.
Services.WebService (?? ? ????????????) - ????????????? ?? 1 ??? ??????? Web ??????
lt_at_ WebService Language"C" Class"SomeService"
gt
WebMethod public void SomeMethod()
32Web-?????? ??????
33??????????? ?? Web ??????
- Web ???????? ?? ?????????? ?? ASP.NET, ?????
Web-???????????? - ?????????? ?? ??????? ?? IIS (Internet
Information Server) - ?? ??????????? ?? Web ?????? ?? ??????????
??????? ?????????? ???? ????????? ?????????? ??
Web ??????? - ????? ?? ?? ?????????? ????? Web-????????????
- Web.config
- Global.asax
34???????????? 1
- ?????? ????? Web ?????? ??????????? ? ????????
35?????????? ?? Web ??????
- ? .NET Framework ?? ??????????? ?? Web ?????? ??
????????? ?. ???. ?????? ??????? - ?????? ?????????
- ????????? ?? ?? WSDL ??????????? ?? Web ????????
(http///service?wsdl) - ????????????? ???? ??? ?? C (VB.NET, )
- ???????????? ???????? ?? .NET ??? SOAP ?????? ?
SOAP ?????????? ??? .NET - ???????????? .NET ???????? ? XML ? ?????????
(marshalling)
.NET ??????
SOAP ??????
??????
??????
Web ??????
36?????????? ?? ?????? ????
- ?????? ????????? ?? ????????? ? ??????????? wsdl
- ??????
- ?????????? ? ?????? ?????? AddService.cs
- ?? ????? ????? XXX ?? ????????? 3 ?????? ?
??????????? ????????? - XXX() ?? ????????? ?????????
- BeginXXX() ? EndXXX() ?? ?????????? ?????????
wsdl http//localhost/Demo-1-AddService/Demo-1-Add
Service.asmx?wsdl
37?????????? ?? ?????? ????
- ???????????? ?? ?????? ????????? ? ????
???????????? ??????? - ?????????? ?? ?????? ??????
- ???????? ?? ?? ????????
- ???????? ????? ?? ??????????? SoapException ???
WebException - ??? ??????? ?? ?????????? ?? Web ???????? ??????
?? ?? ???????? ?????? ?????? ??????
AddService addSevice new AddService() int sum
addService.Add(5, 6)
38???????????? 2
39Web ???????? ? VS.NET
- Visual Studio .NET ??? ????? ????????? ?? Web
?????? - ????????? ?? Web ??????
- ??????????? ?? Web ??????
- ??????????? ?????????? ?? ?????? ???? ?? WSDL
??????????
40???????????? 3
- ????????? ?? Web ?????? ? VS.NET
41???????????? 4
- ??????????? ?? Web ?????? ? VS.NET
42???????? ?? Web ????????
- ????????? WebService
- ?????? ???????? ?? Web ????????
- Namespace ?????? XML ????????????, ?????
???????????? ???????? ???????? - Name ??? ?? ????????
- Description ???????? ???????? ?? ????????
- ????????? WebMethod
- ??????, ?? ????? ????? ? ???????? ?? ????????? ??
Web ???????? - EnableSessiontrue ????????? ?????????? ??
????? - Description ???????? ???????? ?? ??????
43???????? ?? ???????? ??????
WebService( Description"Demo Web service
" " demonstrates complex type
marshalling.", Namespace"http//www.devbg.org
/services/" "Demo_5_Service_Types/2004/1
2/17", Name"Demo 5 - Service Types") public
class TypesService System.Web.Services.WebServic
e ... WebMethod(
Description"Calculates distance "
"between two points in the plane.",
EnableSessiontrue) public Issue GetIssues()
...
44??????????? ?? ??????
- ????????????? ?? ???????? (type marshalling) ?
.NET Framework ?? ???????? ??????????? - ???????? ?? ?????????? XML ????????????
- ???? ????????? ? ??????? ???????? ?? ????????
????? ?? ????? ??????????
45??????????? ?? ??????
- ???? ????????? ? ??????? ???????? ?? ????????
????? ?? ????? ??????????
46???????????? 5
- ??????????? ?? ?????? ?????? Web ????????
47???????????? 6
- ??????????? ?? ?????? ?????? ?????? ?? Web
????????
48???????????? 7
49?????????? ?????????
- ???????????? ????????? ?? ???????? ???
????????????? ???????? ? Web ?????? - ?? ?????????? ?????????? ? ?????? ????? ???
?????? BeginXXX() ? EndXXX() - ??? ?????????? ???????? ??????? ??????? ????? ??
??????? ????????? (callback)
public void static Main() AsyncCallback cb
new AsyncCallback(CallFinished)
service.BeginLongProcess(params, cb,
service) private void CallFinished(IAsyncResult
asyncResult) Console.WriteLine("Async call
completed.")
50???????????? 8
- ?????????? ????????? ?? Web ??????
51Web ?????? ? ?????? ? ?????
- Web ???????? ????? ?? ????????? ?? ?????? ??
??????? - ?????????? ?? ?????????? DataSet ?????? ???
?????? ? ????? - Web ???????? ?????????
- ??????????? ?? ?????
- ????????? ?? ?????
????????? ?? Web ??????
?????????? ?a SQL ??????
???????? ?? SQL ??????
XML
DataSet
?????? ?? ?????????? ?????????
??????? ?? ????????? XML
DataSet
52???????????? 9
- ?????? ?? ????? ???? Web ?????? ????????
53???????????? 10
- ?????? ?? ????? ???? Web ?????? ???????????
??????????
54????????? ?? ?????
- ASP.NET Web ???????? ????????? ?????, ?????
?????? Web ?????????? - Session ??????? ???????? ?????
- Application ??????? ????????? ?? Web
???????????? - ??????????? ?? ??????? ??? ????????
- ??????????? ?? ??????? ??? ???????
WebMethod(EnableSessiontrue)
MyService myService new MyService() myService.C
ookieContainer new System.Net.CookieContaine
r()
55???????????? 11
- ?????????? ?? ????? Web ??????
56???????????? 12
- ?????????? ?? ????? ?????? ?? Web ????????
57Web ?????? ? ASP.NET
????????
58??????????
59?????????? ??????????
- MSDN Library http//msdn.microsoft.com
- ????? ????????, ?????? ? XML http//www.nakov.
com/dotnet/2003/lectures/Working-with-XML.doc - MSDN Training, Developing XML Web Services Using
Microsoft ASP.NET (MOC 2524B) - Enterprise Application http//c2.com/cgi/wiki?En
terpriseApplication - Consuming a DataSet from an XML Web Service, MSDN
Library http//msdn.microsoft.com