Top Banner
Intesar G Ali I Intesar G Ali I T Department T Department Palestinian Land Authorit Palestinian Land Authorit y y Web services Web services Prepared by: Prepared by: Intesar Ali Intesar Ali IT Department IT Department PLA PLA August 2010 August 2010
22

Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Mar 30, 2015

Download

Documents

Shirley Vine
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

Web servicesWeb services

Prepared by:Prepared by:

Intesar AliIntesar Ali

IT DepartmentIT Department

PLAPLA

August 2010August 2010

Page 2: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

XMLXML

XML stands for XML stands for eeXXtensible tensible MMarkup arkup LLanguageanguage

XML is designed to transport and store data. XML is designed to transport and store data. XML is a markup language much like HTML XML is a markup language much like HTML XML was designed to carry data, not to display data XML was designed to carry data, not to display data XML tags are not predefined. You must define your XML tags are not predefined. You must define your

own tags own tags

XML is used to encode all communications to a Web XML is used to encode all communications to a Web serviceservice

Page 3: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

Well Formed XML Documents XML documents must contain a XML documents must contain a root elementroot element. This element is "the parent" of . This element is "the parent" of

all other elements. all other elements.

<root><root>  <child>  <child>    <subchild>.....</subchild>    <subchild>.....</subchild>  </child>  </child></root></root>

XML tags are case sensitive XML tags are case sensitive

attributes provide additional information about elements: attributes provide additional information about elements:

XML Attribute Values Must be Quoted XML Attribute Values Must be Quoted <title lang="en">Everyday </title><title lang="en">Everyday </title>

All XML Elements Must Have a Closing Tag All XML Elements Must Have a Closing Tag

XML Elements Must be Properly NestedXML Elements Must be Properly Nested <b><i>This text is bold and italic</i></b><b><i>This text is bold and italic</i></b> Comments in XML Comments in XML <!-- This is a comment --><!-- This is a comment --> XML Errors Will Stop You XML Errors Will Stop You

Page 4: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

XSD (XML Schema Definition)XSD (XML Schema Definition)An XML schema describes the structure of an XML document.An XML schema describes the structure of an XML document.

defines elements & attributes that can appear in a defines elements & attributes that can appear in a document document

defines which elements are child elements & order , defines which elements are child elements & order , number of child elements number of child elements

defines the defines whether an element is empty or can defines the defines whether an element is empty or can include textinclude text

defines default and fixed values for elements and defines default and fixed values for elements and attributesattributes

defines data types for elements and attributes defines data types for elements and attributes

ex : The value of age cannot be lower than 0 or greater ex : The value of age cannot be lower than 0 or greater than 120than 120

Page 5: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

XSD - The <schema> XSD - The <schema> ElementElement

The <schema> element is the root element of every XML The <schema> element is the root element of every XML SchemaSchema

<xsd:schema> … </xsd:schema> <xsd:schema> … </xsd:schema>

<xsd:element name="lastname" type="xs:string"/ ><xsd:element name="lastname" type="xs:string"/ >

<xsd:attribute name="xxx" type="yyy"/><xsd:attribute name="xxx" type="yyy"/>

Page 6: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

Employee Information SSNNameDateOfBirthEmployeeTypeSalary

XML document for the Employee XML document for the Employee Information Information

<?xml version<?xml version="="1.01.0" " ?> ?> - - <Employees ><Employees >

<Employee><Employee> <SSN>737333333<<SSN>737333333<//SSN> SSN> <Name>ED HARRIS<<Name>ED HARRIS<//Name> Name> <DateOfBirth>1960-01-01<<DateOfBirth>1960-01-01<//

DateOfBirth> DateOfBirth>

<EmployeeType>FULLTIME<EmployeeType>FULLTIME<<//EmployeeType> EmployeeType>

<Salary>4000<<Salary>4000<//Salary> Salary>

<<//Employee> Employee>

<<//Employees> Employees>

XML Schema for the Employee Information XML Schema for the Employee Information

<xsd<xsd::schema schema xmlnsxmlns::xsdxsd="="httphttp://://wwwwww..w3w3..orgorg//20012001//XMLScheXMLSchemama"">>

<xsd<xsd::element nameelement name="="EmployeeEmployee" " minOccursminOccurs="="00" "

maxOccursmaxOccurs="="unboundedunbounded""> >

<xsd<xsd::complexType> complexType> <xsd<xsd::sequence> sequence>

<xsd<xsd::element nameelement name="="SSNSSN="="xsdxsd::string>string>

<xsd<xsd::element nameelement name="="NameName" " typetype="="xsdxsd::stringstring"/"/> >

<xsd<xsd::element nameelement name="="DateOfBirthDateOfBirth" " typetype="="xsdxsd::datedate"/"/> >

<xsd<xsd::element nameelement name="="EmployeeTypeEmployeeType" " typetype="="xsdxsd::stringstring"/"/>>

<xsd<xsd::element nameelement name="="SalarySalary" " typetype="="xsdxsd::longlong"/"/> >

<<//xsdxsd::sequence> sequence> <<//xsdxsd::complexType>complexType> <<//xsdxsd::element> element> <<//xsdxsd::schema> schema>

Case StudyCase Study

Page 7: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Web Services Web Services

By using Web services, your application can publish its function By using Web services, your application can publish its function or message to the rest of the world.or message to the rest of the world.

Web services use XML to code and to decode data,Web services use XML to code and to decode data, and SOAP to transport it.and SOAP to transport it.

XML makes it easier to share data among different applications XML makes it easier to share data among different applications So Windows applications can talk with Unix applications. So Windows applications can talk with Unix applications.

Page 8: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

A Web Service ExampleA Web Service Example In the following example we will use ASP.NET to create a simple Web Service that converts In the following example we will use ASP.NET to create a simple Web Service that converts

the temperature from Fahrenheit to Celsius, and vice versa:the temperature from Fahrenheit to Celsius, and vice versa:

<%@ WebService Language="VBScript" Class="TempConvert" %><%@ WebService Language="VBScript" Class="TempConvert" %>

Imports SystemImports SystemImports Imports System.Web.ServicesSystem.Web.Services

Public Class TempConvert :Inherits WebServicePublic Class TempConvert :Inherits WebService

<WebMethod()><WebMethod()> Public Function HelloWorld( ByVal lcName As String) As StringPublic Function HelloWorld( ByVal lcName As String) As String return "Hello World, " + lcNamereturn "Hello World, " + lcName

end functionend function

    <WebMethod()><WebMethod()> Public Function AddNumbers (ByVal lnNumber1 As decimal, ByVal lnNumber2As Public Function AddNumbers (ByVal lnNumber1 As decimal, ByVal lnNumber2As

decimal) as decimaldecimal) as decimalreturn lnNumber1 + lnNumber2return lnNumber1 + lnNumber2

end functionend function

<WebMethod()> <WebMethod()> public function GetServerTime() as DateTimepublic function GetServerTime() as DateTime

return DateTime.Nowreturn DateTime.Nowend class end class

Page 9: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

Web ServiceWeb Service Use "WebMethod()" to convert the functions in Use "WebMethod()" to convert the functions in

your application into web services:your application into web services:

Publish the .asmx file on a server with .NET Publish the .asmx file on a server with .NET support, and you will have your first working support, and you will have your first working Web Service.Web Service.

ASP.NET Automates the Process, you do not ASP.NET Automates the Process, you do not have to write your own WSDL and SOAP have to write your own WSDL and SOAP documents.documents.

Page 10: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

Web Services Platform Web Services Platform ElementsElements

Web Services have three basic platform Web Services have three basic platform elementselements: :

SOAPSOAP WSDL WSDL UDDI UDDI

Page 11: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

What is SOAP?What is SOAP?

SOAP is an XML-based protocol for exchanging information SOAP is an XML-based protocol for exchanging information between computers over HTTP.between computers over HTTP.

Or more simple: SOAP is a protocol for accessing a Web Or more simple: SOAP is a protocol for accessing a Web Service.Service.

SOAP stands for SOAP stands for Simple Object Access ProtocolSimple Object Access Protocol SOAP is a communication protocolSOAP is a communication protocol SOAP is a format for sending messagesSOAP is a format for sending messages SOAP is designed to communicate via Internet SOAP is designed to communicate via Internet SOAP is platform independentSOAP is platform independent SOAP is language independentSOAP is language independent SOAP is based on XMLSOAP is based on XML SOAP allows you to get around firewallsSOAP allows you to get around firewalls

Page 12: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

SOAP requestSOAP request

<?xml version="1.0"?><?xml version="1.0"?><soap:Envelope <soap:Envelope

xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" instance" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope">xmlns:soap="http://schemas.xmlsoap.org/soap/envelope">

<soap:Body><soap:Body> <AddNumbers xmlns="http://tempuri.org/"><AddNumbers xmlns="http://tempuri.org/"> <lnNumber1><lnNumber1>66</lnNumber1></lnNumber1> <lnNumber2>4</lnNumber2><lnNumber2>4</lnNumber2> </AddNumbers></AddNumbers> </soap:Body></soap:Body></soap:Envelope></soap:Envelope>

passing in the two provided parameters, which are properly passing in the two provided parameters, which are properly converted into the types specified by the WSDL file.converted into the types specified by the WSDL file.

Page 13: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

SOAP responseSOAP response

  <?xml version="1.0"?><?xml version="1.0"?><soap:Envelope <soap:Envelope

xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" instance" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope">xmlns:soap="http://schemas.xmlsoap.org/soap/envelope">

<soap:Body><soap:Body> <AddNumbersResponse xmlns="http://tempuri.org/"><AddNumbersResponse xmlns="http://tempuri.org/"> <AddNumbersResult><AddNumbersResult>1010</AddNumbersResult></AddNumbersResult> </AddNumbersResponse></AddNumbersResponse> </soap:Body></soap:Body></soap:Envelope></soap:Envelope>

Page 14: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

What is WSDL?What is WSDL?

WSDL is a document written in XML.WSDL is a document written in XML.

A WSDL file describes all the methods and method signatures, as well A WSDL file describes all the methods and method signatures, as well as the namespaces and the handling URL for the Web Service.as the namespaces and the handling URL for the Web Service.

Visual Studio.NET uses the WSDL file to create a Web Reference on the Visual Studio.NET uses the WSDL file to create a Web Reference on the client side from your Web Service. client side from your Web Service.

It reads the WSDL file and based on the definitions found in the WSDL It reads the WSDL file and based on the definitions found in the WSDL file creates a proxy class that mimics the interface of the Web file creates a proxy class that mimics the interface of the Web Service. Service.

Because this class is actually linked into your client project the class Because this class is actually linked into your client project the class becomes available in IntelliSense and you can actually see the full becomes available in IntelliSense and you can actually see the full interface of the class as you type.interface of the class as you type.

Page 15: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

The WSDL Document The WSDL Document StructureStructure

A WSDL document describes a web service using these major elements:A WSDL document describes a web service using these major elements:

<definitions><definitions>

<<typestypes>The data types used by the web service>The data types used by the web service</types></types>

<<messagemessage>The messages used by the web service >The messages used by the web service </message></message>

<<portTypeportType>The operations performed by the web service>The operations performed by the web service</portType></portType>

<<bindingbinding>The communication protocols used by the web service >The communication protocols used by the web service </binding></binding> Binding to SOAPBinding to SOAP

</definitions> </definitions>

<http<http://://wwwwww..mycompanymycompany..comcom//SampleWebServiceSampleWebService..asmx?wsdl>.asmx?wsdl>.

Page 16: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

What is UDDIWhat is UDDI??

UDDI stands for UDDI stands for Universal Description, Discovery and IntegrationUniversal Description, Discovery and Integration

The purpose of UDDI is to allow users to discover available web services The purpose of UDDI is to allow users to discover available web services and interact with them dynamically. The process can be divided into three and interact with them dynamically. The process can be divided into three phases: Searching (discovery), Binding, and Executing. phases: Searching (discovery), Binding, and Executing.

UDDI is a directory service where companies can register and search for UDDI is a directory service where companies can register and search for Web services.Web services.

UDDI is a directory for storing information about web servicesUDDI is a directory for storing information about web services UDDI is a directory of web service interfaces described by WSDLUDDI is a directory of web service interfaces described by WSDL

UDDI is often compared to a telephone book's white, yellow, and green UDDI is often compared to a telephone book's white, yellow, and green pages. The project allows businesses to list themselves by name, product, pages. The project allows businesses to list themselves by name, product, location, or the Web services they offer. location, or the Web services they offer.

Page 17: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

there are two primary way to create Web Services in there are two primary way to create Web Services in

ASP. netASP. net

.asmx file .asmx file

You can use You can use Windows Communication Foundation Windows Communication Foundation WCF WCF to create web service to work with variety to create web service to work with variety protocols like TCPprotocols like TCP

In asp.net 3.0In asp.net 3.0

Page 18: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

Testing the Web ServiceTesting the Web Service http://localhost/codeservice/firstwebservice.asmxhttp://localhost/codeservice/firstwebservice.asmx

  

   

Page 19: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

Page 20: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

Calling the Web Service on the client sideCalling the Web Service on the client side

Page 21: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

22 - -Adding a Web ReferenceAdding a Web Reference

Page 22: Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.

Intesar G Ali Intesar G Ali IT Department IT Department

Palestinian Land Authority Palestinian Land Authority

THANK YOU THANK YOU