develop asp.net web service

104
Developing XML Web Service using MS ASP.NET 2008 It doesn't matter how fast technology moves as long as we are building our own technology 06/28/2022 Safaa Farouk-ITI 1 E- Busines s E - B U S I N E S S

Upload: safaa-farouk

Post on 13-Apr-2017

201 views

Category:

Technology


0 download

TRANSCRIPT

Developing XML Web Service using MS ASP.NET 2008

Developing XML Web Service using MS ASP.NET 2008It doesn't matter how fast technology moves as long as we are building our own technology7/13/2016Safaa Farouk-ITI 1E-BusinessE-BUSINESS

1

Course OutlineDay 1Module 1: The Need for XML Web ServicesModule 2: XML Web Service ArchitecturesModule 3: Implementing a Simple XML Web ServiceDay2 Module 4: The Underlying Technologies of XML Web ServicesModule 5: Consuming XML Web ServicesDay3 Module 6: Deploying XML Web ServicesModule 7: Securing XML Web ServicesModule 8: Designing XML Web Services

7/13/2016Safaa Farouk-ITI 2E-Business

2

Session CautionsYou can talk anytime. You can go anywhere.You can answer any kind of calls.You can ask for whatever you want. Actually

You can do anything you want!!!

E-Business

7/13/2016Safaa Farouk-ITI 4

Module 1 :The Need for XML Web Service

E-Business

Before we have been talking about XML web service we have to know some key points (principles)

The need means in marketing fundamental that there is something people need to (do , have , use ) but they didnt find the way within the available resources.

So lets know the need(what actually people want to make ) , the resources(the available technology ) , the reason(why this resources can not meet their need). 4

Applications Architecture

7/13/2016Safaa Farouk-ITI 5E-Business

Any application has its own architecture5

Applications Architecture cont Single Tier(Mainframe based)

User Services, Data Services and Business Services are centralized in one application.Dumb terminals are connected to mainframeAdvantages :Deploying.Maintenance.Disadvantage:Scalability.Processing.

7/13/2016Safaa Farouk-ITI 6E-Business

business logic , presentation logic and data storage are centralized in one applicationData services + business services + user services in one applicationTerminals -> Centralize business logic + Deploying + maintenance

Scalability, Processing 6

Applications Architecture cont Two- tiers

Processing is shared between client and server .Application talking to backend DBUser services places in client sideData services places in server side Business services ?

7/13/2016Safaa Farouk-ITI 7E-Business

Processing is shard between Client And serverUser services places in client side , data services places in server side Business services place in client side=intelligent client based architecture when business change -> client version released

Business services place in server side=intelligent server based architecture (processing)stored procedure is not flexible and efficient more than implementing it using programming (crud create delete update retrieve )

Business services be shared between client and server

adding more logical tiers to your application or placing your application files on different computers doesn't make your application distributed7

Applications Architecture cont N-tiers

Data services reside in database server .Business services reside in a application server .User services reside in client side .

7/13/2016Safaa Farouk-ITI 8E-Business

Data services reside in a database server sideUser services reside in client side Business services reside in server side (may be separated in N-layer)1- migrate from oracle to SQL middle tier that talking to database will be changed2-business tier (code to enforce business rules)

Implementation such business objects using COM DCOM CORBA,RMI,REMOTING(Remote Object based ),RPC,Web server8

Web based applicationClient side applicationWeb sites were simple collections of single pages that interact togetherHTML,JSServer-side applicationsThey had become individual applications ASP,PHP,JSP

7/13/2016Safaa Farouk-ITI 9E-Business

Web sites became a Web-based front end.HTML request ,HTML responseThey could design Business components just like any other three-tier application9

XML

XML has been a corner stone in the development of the programmable Internet.XML is designed as a metalanguage. That is, it provides the foundation for marking up anything we want in plain text.By using XML to mark up data, we can make that data available in a platform-neutral format that can be shared online regardless of the operating system, database, and firewalls the host platform uses.7/13/2016Safaa Farouk-ITI 10E-Business

HTML, which is designed to identify and mark up the various elements in a Web page

10

Distributed ApplicationsWhat is a distributed application?A distributed application is an application whose processing requirements may be satisfied by multiple physical computers, and whose data may be stored in many physical locations.

7/13/2016Safaa Farouk-ITI 11E-Business

-A distributed application is an application whose processing requirements may be satisfied by multiple physical computers, and whose data may be stored in many physical locations, but whose logical function is not determined by the physical topology that is used to implement the application.

RPC Based Architecture:

-Applications splitting their workload privately and securely over more than one machine, using their systems own Remote Procedure Call (RPC) protocol to call methods( synchronously) and send information from machine to machine to machine as if they were all the same machine. Message Based Architecture: Message-Oriented Middleware provides applications with interprocess communication services by using message queuing technology as the basis for a guaranteed service level for critical applications(Asynchronously)

11

Why Distributed ApplicationsCost of mainframesData ownershipNo single point of failureShared processing

Distributed applications as service providers

7/13/2016Safaa Farouk-ITI 12E-Business

The need of Distributed-Applications Cost of mainframes: has a single point of failure Data ownership :sites that owned the data did not like to delegate the responsibility of managing their data to some other central location. Security: sensitive corporate data still must be secured.

To reach the goal of reuse, it became useful to view the distributed components of an application as providers of services to a logical application.Application=provider of services

12

Distributed Applications contthe architectures and frameworks on which distributed applications were builtRMI(remote method invocation).NET RemotingCORBA(Common Object Request Broker Architecture)DCOM(Distributed Component Object Model)

7/13/2016Safaa Farouk-ITI 13E-Business

13

Problems with Distributed ApplicationsThe machines were tightly coupled.InteroperabilityMachines compatibilityData formats.Firewalls.Server failures or loss of server response.Client failures.Retrying a call .

7/13/2016Safaa Farouk-ITI 14E-Business

The machines were tightly coupled together, and each architecture had its own RPC protocol, message format, and message description language

Interoperability : Each architecture had its own RPC protocol, message format, and message description language. DCOM, CORBA, Java RMIworked exclusively with themselves. An application written in CORBA would not cooperate withor, indeed, understandthe same application written in DCOM or Java RMI on another machine, and vice-versa.

Machines compatibility: Your machines setups had to be almost identical to get a distributed application to work at all.

Data Format: You must consider how to handle data types that are not compatible across different systems.

Fire Walls : Not only must you consider authentication and authorization, but you also must consider how to secure the communication between machines, and how to guard against several attacks.

Server Failure: Failure of any point can cause the entire distributed application to fail. Therefore, you must consider how to handle server failures and loss of server response .

Client Failure: If client fails, then you must consider how the server will be notified. You also must consider if it is necessary to reclaim resources on the server that were in use by the client.

Recalling methods: Recall method that already executed but the server didn't give any notification to the client or may it be lost.

14

Building a New Technology

7/13/2016Safaa Farouk-ITI 15New TechnologyBinary CallsPlatform-Natural Calls Distributed Application Web based ApplicationE-Business

15

What they need?A platform-independent format language for structured data exchange.A way of describing the structure of the data being exchangedA standard method of packaging the data for transmission over the InternetA way for Web services to describe their public interface to clientsA framework for programmatically locating Web services via their capabilities or description

7/13/2016Safaa Farouk-ITI 16E-Business

16

Evolution of web service7/13/2016Safaa Farouk-ITI 17XMLHttpData formatscompatibilityFirewalls friendlyRPC callsE-BusinessService

how could they (XML , HTTP) transform RPC calls over a proprietary protocol into something any system could receive and understand?17

The AnswerSOAP (Simple Object Access Protocol)XML based application that is a message template for sending request and receiving response to web services between the browser and web service. WSDL (Web service description language)WSDL able to describe the service details to the client UDDIstandard for Web service cataloging, UDDI server lets you store the contact locations of your Web service7/13/2016Safaa Farouk-ITI 18E-Business

SOAP message(Request/Response) is written in plain XML text and adheres to the SOAP standard, so any system can understand what it says and act accordingly

How to describe the interface between the client and service and the required resources(the type and structure of the calls, required parameters, return values, protocol bindings)

18

Introducing Web Services

What are Web services?Web service is a method of making information available in a standardized way that could be accessed by any developers applications over the web.

7/13/2016Safaa Farouk-ITI 19E-Business

Web Service : URL-addressable set of functionality exposed over a network.19

Web services and .NET

7/13/2016Safaa Farouk-ITI 20

System.Net.SocketsSystem.NetSystem.Runtime.RemotingSystem.Web.ServicesE-BusinessTCP/IPHTTPBinary callsLoosely coupling components

20

Now,Before you start to learn how to make a new thing look at what it really do .http://uddi.microsoft.comhttp://www.webservicex.nethttp://www.webservicelist.comhttp://www.webserviceoftheday.comhttp://www.wsiam.com

7/13/2016Safaa Farouk-ITI 21E-Business

.asmx file: front-end for a Web service that is implemented by using ASP.NET.21

Why web serviceInteroperability.Any web service can interoperate with any other web service.Any network node that support both XML and HTTP can host and access Web service.Multi language support.Use of industry supported standards.7/13/2016Safaa Farouk-ITI 22E-Business

Notices about WSFirst: would you use your WS or just use the ready made one ?No guarantee it will be exist next day.No guarantee it will be with the same cost.Second : the lack of education People are still unaware of what web service can offer.Third : the magic of your worka good web service should exist in your application while the user should never know its there

7/13/2016Safaa Farouk-ITI 23E-Business

.asmx file: front-end for a Web service that is implemented by using ASP.NET.23

TipThink of a web service thats can be used in a lot of applications.Try to make it Let others share it for freeThenOoh ,its been Gone Learn how to make money

7/13/2016Safaa Farouk-ITI 24E-Business

24

7/13/2016Safaa Farouk-ITI 25Module 2 XML Web Service Architectures

E-Business

Service-Oriented Architecture (SOA)7/13/2016Safaa Farouk-ITI 26E-Business

Service Broker

Service Provider

Service Consumer

PublishFindBind

SOA:-It is a conceptual architecture for implementing dynamic, loosely coupled, distributed applications.SOA consists of 3 roles:

Service Provider : A service provider is a node on the network (intranet or Internet) that provides access to the interface to a software service that performs a specific set of operation.Service consumer: A service consumer is a node on the network that binds to a service from a service provider and uses the service to implement a business solution. Service broker : A service broker is a node on the network that is a repository of service descriptions and can be used like an address book to find the location of service.

Basic operations : 1-Publish services Service providers publish their services to a service broker. The information published includes the service interface definition, location of service providers, and possibly other supporting information or documentation.

2-Find services Service consumers find required/desired services by using a service broker. 3-Bind to services Service consumers bind to specific services that are provided by a service provider.

26

Web Service Architectures7/13/2016Safaa Farouk-ITI 27E-Business

UDDI (Web Service Broker)

Web Service ProviderIIS

Web Service ConsumerAny client

SOAPSOAPSOAP

Internet

The basic elements in a Web service architecture are: -The Web service provider: which is a network node hosting a Web service, node that hosts a registry.

-The Web service consumer: which is a network node hosting any client can communicate by using Hypertext Transfer Protocol (HTTP)

-The Web service broker(Universal Description, Discovery, and Integration (UDDI)): which is a network node hosting a global registry of available Web services much like a global address book

27

Roles in a Web Services ArchitectureThe Web Service Provider.

The Web Service Consumer.

The Web Service Broker.

7/13/2016Safaa Farouk-ITI 28E-Business

Web Service Types

Simple Services.

Application Integration services.

Business Integration services

Commercial Web services

Framework services.

7/13/2016Safaa Farouk-ITI 29E-Business

Simple Service: Service that provides a simple piece of functionality to the client, data retrieval or simple calculations Application Integration Services: service that works as intermediary between applications that wouldnt normally be able to talk with each other because they were written for different platforms or use different component architectures.

.NET client running on Windows 2000 can easily invoke a Java Web service running on mainframe or Unix machine to retrieve data from a legacy application. Organizations can send electronic purchase orders to suppliers and receive electronic invoicescommercial Web services target applications not humans as their direct users, Continental Airlines exposes flight schedules and status Web services for travel Web sites and agencies to use in their applications. 29

Remoting Vs Web servicesProtocol

State Management Type System Interoperability Reliability

Extensibility

Ease-of-Programming E-Business

Protocol Web Services:Can be accessed only over HTTP Remoting: Can be accessed over any protocol (including TCP, HTTP, SMTP and so on) State Management Web service: Web services work in a stateless environment Remoting: Provide support for both stateful and stateless environments through Singleton and SingleCall objects Type System Web service:Web services support only the datatypes defined in the XSD type system, limiting the number of objects that can be serialized. Remoting: Using binary communication, .NET Remoting can provide support for rich type system Interoperability Web service: Web services support interoperability across platforms, and are ideal for heterogeneous environments. Remoting: .NET remoting requires the client be built using .NET, enforcing homogenous environment. Reliability Web service: Highly reliable due to the fact that Web services are always hosted in IIS Remoting: Can also take advantage of IIS for fault isolation. If IIS is not used, application needs to provide plumbing for ensuring the reliability of the application. Extensibility Web service: Provides extensibility by allowing us to intercept the SOAP messages during the serialization and deserialization stages. Remoting: Very extensible by allowing us to customize the different components of the .NET remoting framework. Ease-of-Programming Web service: Easy-to-create and deploy. Remoting:Complex to program.

30

7/13/2016Safaa Farouk-ITI 31Module 3 Implementing a Simple XML Web Service

E-Business

Creating Web ServiceEvery web service you create must have basically 4 itemsProcessing Directive

NameSpacesSystem.webSystem.web.servicesSystem.web.services.protocolsPublic class[webservice ] public class Myservice:System.web.services.webservice {}Web Method [webMethod] public string HelloWS() { retrun Hello My first web sevice }

7/13/2016Safaa Farouk-ITI 32

Creating a Web Service Project

Create A web service project7/13/2016Safaa Farouk-ITI 33E-Business

33

Web Service AttributesWebService Class Attributes:WebService PropertiesDescription NameNamespaceWebServiceBinding PropertiesConformsToEmitConformanceClaimsLocationNameNameSpace

7/13/2016Safaa Farouk-ITI 34E-Business

Name Space =URL where you are hosting the XML Web service.Name = enables you to change how the name of the Web service is presented to the developer via the ASP.NET test page Description = Description allows you to provide a textual description of the Web service.

Web Service Binding

34

Web Method AttributeWeb Method Attributes BufferResponseCacheDurationDescriptionEnableSessionMessageNameTransactionOption

7/13/2016Safaa Farouk-ITI 35E-Business

Buffer response= the response from the XML Web service is held in memory and sent as a complete package=true [WebMethod(BufferResponse=false)] Setting BufferResponse to false makes sense only when the web service returns a large amount of data.

Cache Duration=Specifies the number of seconds that the response should be held in the systems cache Default=0Description=Applies a text description to the WebMethod that appears on the .aspx test pag

EnableSession=enable session state for a particular method

MessageName=give unique name for a method(required in overloaded )

TransactionOption= transaction options disabled-supported-notsupported-required-requirednew using System.EnterpriseServices; [WebMethod(TransactionOption=TransactionOption.RequiresNew)] public DataSet TransactionMethod() 35

Web Service data typesWeb service has a limitation on the data type of the passing parameters or the return result,This limitation are designed to ensure cross platform compatibilityPrimitive data types and stringsEnumerationDataSet and DataTableXMLNodeCustom ObjectArrayList and collections

7/13/2016Safaa Farouk-ITI 36E-Business

36

Lab Assignment MazadWS7/13/2016Safaa Farouk-ITI 37E-Business

7/13/2016Safaa Farouk-ITI 38Module 4The Underlying Technologies of XML Web ServicesE-Business

Allied technology

SOAPWSDLDISCOUDDI7/13/2016Safaa Farouk-ITI 39E-Business

SOAPSimple Object Access Protocol7/13/2016Safaa Farouk-ITI 40E-Business

SOAP overviewSimple Object Access Protocol (SOAP) is a lightweight protocol ( XML based ) intended for the exchange of structured information in decentralized, distributed environments.is a message template for sending request and receiving responses to web services between the browser and web service SOAP elements SOAP EnvelopeSOAP HeaderSOAP BodySoap Fault7/13/2016Safaa Farouk-ITI 41E-Business

SOAP Envelope : The Envelope element is the root node of an XML document that represents the SOAP message. It contains the Header and Body elements and is mandatory. SOAP Header: The Header element is the first immediate child element of the SOAP Envelope element.

SOAP Body : If the SOAP Envelope element does not contain the Header element, then the Body element must be the first immediate child element of the Envelope. If the Header element is present, then the Body element must immediately follow the Header element.

SOAP Fault : is used to transport error or status information or both, within a SOAP message. If the SOAP Fault element is present, it must be a body entry and may not appear more than once within the Body element.

The faultcode element :is intended for use by the Web service consumer to identify the fault. This element must be present within the SOAP Fault element.

faultstring :The purpose of the faultstring element is to provide a human-readable explanation of the fault. It must be present within the SOAP Fault element and must provide information explaining the nature of the fault.

faultactor :The purpose of the faultactor element is to provide information about who caused the fault to happen within the message path. It indicates the source of the fault. The value of the faultactor element is a URI that identifies the source.

detail : is for holding application-specific error information related to the Body element. It is included if the contents of the Body element could not be successfully processed. 41

SOAP and HTTPData you put wrapped up by three ways HTTP-getHTTP-postSOAPWeb service life cycle client calls a web service. client invoke a specific method. server returns values or an acknowledgments.client acts on information or call another web service.

7/13/2016Safaa Farouk-ITI 42E-Business

.asmx file: front-end for a Web service that is implemented by using ASP.NET.42

SOAP and HTTP cont

When you type http://www.webservice.com/mywebservice, You decide the protocol that you are using HTTPService locationAsp.net passes information backward and forward using http-request /http-response

7/13/2016Safaa Farouk-ITI 43E-Business

43

Your request has the following infoWeb services URLThe fact that it is an http requestThe amount of informationThe type of doc you want back from the web service Information about the client The date of the requestThe parameters you want to send to web service Browser collects this information and wraps it up in a document ready for transmission serialization in the form of xml document.

7/13/2016Safaa Farouk-ITI 44E-Business

.asmx file: front-end for a Web service that is implemented by using ASP.NET.44

Http overviewStateless protocol.Http Request

Http Response

7/13/2016Safaa Farouk-ITI 45E-Business

Request-Method URL versionHeaders

Message bodyVersion status-code descriptionHeaders

Message Body

HTTP is a stateless protocol: This means that whenever the client makes a request, the connection to the server is closed after the client receives the response.

Request method : POST-GET-Connect

URL: resource location Headers: Host name , content type , content length ,

Message body : query string or parameters is exist45

Post vs. Get Request methodsHttp - Get

Http- Post7/13/2016Safaa Farouk-ITI 46E-BusinessGET URL/Path? query string versionHost: host name

POST URL/path versionHost: host nameHeaders

Query string

46

SOAP messageSOAP Request

SOAP Response

7/13/2016Safaa Farouk-ITI 47

int

int int

E-Business

SOAP cont7/13/2016Safaa Farouk-ITI 48E-Business

int

E-Business

Secure CommunicationUsing SSLNeed digital certificationUsing custom SoapExtensionAttributeDifficult to implement7/13/2016Safaa Farouk-ITI 104E-Business

104