Date post: | 03-Jan-2016 |
Category: |
Documents |
Upload: | bruno-garrett |
View: | 218 times |
Download: | 4 times |
Web ServicesWeb Services
ASP.NET Web ServicesASP.NET Web Services Goals of ASP.NET Web services:Goals of ASP.NET Web services:
To enable cross-platform, cross-To enable cross-platform, cross-business computingbusiness computing
Great for “service” based operations Great for “service” based operations that have few methods: Google that have few methods: Google searches, Amazon integration, etc.searches, Amazon integration, etc.
ASP.NET Web services are ASP.NET Web services are “method-oriented”, not object-“method-oriented”, not object-orientedoriented Everything is passed by value: no Everything is passed by value: no
references to server objectsreferences to server objects
ASP.NET Web ServicesASP.NET Web Services Usually uses SOAP over HTTP POST – Usually uses SOAP over HTTP POST –
platform independent messagesplatform independent messages Hosted in IISHosted in IIS
Can use built-in authentication and Can use built-in authentication and encryption via IISencryption via IIS
Technically stateless, but can use regular Technically stateless, but can use regular ASP.NET Session variablesASP.NET Session variables
Very easy to use, with good support in Visual Very easy to use, with good support in Visual Studio.NETStudio.NET
Doesn’t support:Doesn’t support: Events / callbacksEvents / callbacks Object referencesObject references
Standards-BasedStandards-Based
SOAP (Simple Object Access Protocol)SOAP (Simple Object Access Protocol) XML-based protocol for messagingXML-based protocol for messaging
WSDL (Web Service Description Language)WSDL (Web Service Description Language) Document describing the message Document describing the message
exchange contractexchange contract
DISCO (Discovery)DISCO (Discovery) Simple protocol for publishing available services Simple protocol for publishing available services
UDDI (Universal Description Discovery and UDDI (Universal Description Discovery and Integration)Integration) Yellow pages directory for servicesYellow pages directory for services
SOAPSOAP Simple Object Access ProtocolSimple Object Access Protocol
XML based protocol to exchange XML based protocol to exchange structured and typed informationstructured and typed information
Remote Procedure Calls (RPC)Remote Procedure Calls (RPC) Serialization Rules (XSD)Serialization Rules (XSD) ExtensibleExtensible
WSDLWSDLWeb Service Definition LanguageWeb Service Definition Language
An XML-based grammar for describing An XML-based grammar for describing the capabilities of Web Servicesthe capabilities of Web Services
ExtensibleExtensible Jointly developed by Microsoft and IBMJointly developed by Microsoft and IBM Similar in concept to IDL, but it’s not IDLSimilar in concept to IDL, but it’s not IDL
To parse WSDL you need XML parserTo parse WSDL you need XML parser
UDDIUDDIUniversal Description, Discovery and IntegrationUniversal Description, Discovery and Integration
A project to speed interoperability A project to speed interoperability and adoption for web servicesand adoption for web services Standards-based specifications for Standards-based specifications for
service description and discoveryservice description and discovery Shared operation of a business registry Shared operation of a business registry
on the webon the web Partnership among industry and Partnership among industry and
business leadersbusiness leaders Open process with clear roadmap to Open process with clear roadmap to
a standards bodya standards body
Publ
ish Find
Bind
Internet
Overview of XML Web Service Overview of XML Web Service ArchitecturesArchitectures
XML Web Service Provider
XML Web Service Consumer
UDDI(XML Web Service Broker)
Web Services As an Implementation of a Web Services As an Implementation of a Service-Oriented ArchitectureService-Oriented Architecture
UDDI
AnyClient
SOAP
SOAP
.NET Web Service
SOAP
IIS
DiscoveryDiscovery
Let me talk to you (SOAP)Let me talk to you (SOAP)
Web Services (In Practice)Web Services (In Practice)
Design-Time or DynamicDesign-Time or Dynamic RuntimeRuntime
http://yourservice.comhttp://yourservice.com
HTML or XML with link to WSDLHTML or XML with link to WSDL
How do we talk? (WSDL)How do we talk? (WSDL)http://yourservice.com/?WSDLhttp://yourservice.com/?WSDL
XML with service descriptionsXML with service descriptions
http://yourservice.com/svc1http://yourservice.com/svc1
XML/SOAP BODYXML/SOAP BODY
Web Web ServiceService
WebWebService Service
ConsumerConsumer
UDDIUDDI
Find a ServiceFind a Servicehttp://www.uddi.orghttp://www.uddi.org
Link to DISCO or WSDL documentLink to DISCO or WSDL document
XML Web Services MappingXML Web Services Mapping
DataData
SchemaSchema
ServicesServices
InvocationInvocation
WebWeb
XMLXML
XSDXSD
WSDLWSDL
SOAPSOAP
ApplicationApplicationConceptsConcepts FrameworkFramework
ObjectsObjects
ClassesClasses
MethodsMethods
CallsCalls
The .NET Framework providesThe .NET Framework providesa bi-directional mappinga bi-directional mapping
Simple ExampleSimple Example
<%@ WebService Language="C#" Class="HelloWorld" %>
using System;
using System.Web.Services;
public class HelloWorld : WebService {
[WebMethod]
public String SayHelloWorld() {
return "Hello World";
}
}
SOAPSOAP
Simple Object Access ProtocolSimple Object Access Protocol
XML-based standard that defines how XML-based standard that defines how method calls can be made over HTTP, method calls can be made over HTTP, and how the server’s response should and how the server’s response should be formattedbe formatted
You need to know it becauseYou need to know it because in certain circumstances where you might in certain circumstances where you might
want to use SOAP to exchange special want to use SOAP to exchange special “meta” information along with each “meta” information along with each method callmethod call
SOAP ElementsSOAP Elements
Envelope (mandatory)Envelope (mandatory) Top element of the XML document representing the Top element of the XML document representing the
messagemessage Header (optional)Header (optional)
Determines how a recipient of a SOAP message Determines how a recipient of a SOAP message should process the messageshould process the message
Adds features to the SOAP message such as Adds features to the SOAP message such as authentication, transaction management, message authentication, transaction management, message routes, etc…routes, etc…
Body (mandatory)Body (mandatory) Exchanges information intended for the recipient of Exchanges information intended for the recipient of
the message. the message. Typical use is for RPC calls and error reporting.Typical use is for RPC calls and error reporting.
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?> <soap:Envelope …> <soap:Envelope …>
<soap:Header> <soap:Header> <AuthHeader xmlns="http://tempuri.org/"> <AuthHeader xmlns="http://tempuri.org/">
<Username>avi</Username> <Username>avi</Username> <Password>xM76w@</Password> <Password>xM76w@</Password>
</AuthHeader> </AuthHeader> </soap:Header> </soap:Header> <soap:Body> <soap:Body>
<Add xmlns="http://tempuri.org/"> <Add xmlns="http://tempuri.org/"> <a>23</a> <a>23</a> <b>44</b> <b>44</b>
</Add> </Add> </soap:Body> </soap:Body>
</soap:Envelope> </soap:Envelope>
POST /HelloWorld/Hello.asmx HTTP/1.1 Host: localhost Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/Add"
SOAP FaultSOAP Fault
Used to carry error and/or status information Used to carry error and/or status information within a SOAP messagewithin a SOAP message
Appears within the SOAP bodyAppears within the SOAP body Defines the following:Defines the following:
faultcode (mandatory)faultcode (mandatory) Faultstring (mandatory)Faultstring (mandatory) faultactor (optional)faultactor (optional) DetailDetail
SOAP Fault ExampleSOAP Fault Example
<SOAP:Fault> <faultcode>SOAP:Server</faultcode> <faultstring>Internal Application Error</faultstring> <detail xmlns:f=“http://www.a.com/CalculatorFault”> <f:errorCode>794634</f:errorCode> <f:errorMsg>Divide by zero</f:errorMsg> </detail></SOAP:Fault>
Soap ExtensionsSoap ExtensionsCreatingCreating
Create a class derived from Create a class derived from SoapExtensionSoapExtension
Create a class derived from Create a class derived from SoapExtensionAttributeSoapExtensionAttributeOverload the constructor if necessaryOverload the constructor if necessaryDefine any custom propertiesDefine any custom propertiesOverload the ‘ExtensionType’ property to Overload the ‘ExtensionType’ property to
return the type of your derived return the type of your derived SoapExtension classSoapExtension class
Apply the attribute to a web method or Apply the attribute to a web method or web service classweb service class
Soap ExtensionsSoap ExtensionsUsesUses
Used for More Advanced FunctionalityUsed for More Advanced Functionality Intercept Calls to a Web ServiceIntercept Calls to a Web Service Intercept Calls to a Web MethodIntercept Calls to a Web Method Pre and Post ProcessingPre and Post Processing
TracingTracingEncryptionEncryptionCompressionCompression