Anda di halaman 1dari 49

Webservice Tutorials

1.1

Web Services Tutorials

Webservice Interview Questions with Answers


2.1 2.2 2.3 2.4

Webservice Subjective Questions with Answers Webservice Interview Questions with Answers Webservice Objective Questions with Answers FAQ

Web Services Tutorials

1. Introduction 2. Why use Web services 3. Characteristic of Web services 4. Components of Web Services 5. Web services Architecture 6. Web Services Flow 7. System Requirements 8. XML-RPC 9. SOAP 10. UDDI 11. WSDL 12. Advantage and Disadvantage 13. How To make a Web Services 14. Create a Web Service for calculate Age, Factorial and Square

root of a number and how to add this to your Web Site 15. How to Use web Services (in ASP. NET) 16. How to Use web Services (in Console Application)
INTRODUCTION
Web Services can convert application into a Web-application that makes it available over the internet. It uses a standardized XML messaging system. In web Environment XML is used to encode all communications to a web service. Client sending an XML message to invoking Web services, and wait for a corresponding XML response. Web services are not tied to any one operating system or programming language. Web Services are self-contained, modular, distributed, dynamic applications that can be described, published, located, or invoked over the network to create products, processes, and supply chains. Web services are developed

on the basis of open standards, that's are TCP/IP, HTTP, Java, HTML, and XML. Web services is a collection of collection of open protocols and standards that use XML-based information exchange systems (programs, objects, messages, or documents) over internet for direct application-to-application interaction. Web Services are: 1. 2. 3. 4. 5. Is available over the Internet or private (intranet) networks Uses a standardized XML messaging system Is not tied to any one operating system or programming language Is self-describing via a common XML grammar Is discoverable via a simple find mechanism

WHY USE WEB SERVICES


Some Issues are Component-based programming has become more popular For example end-to-end e-commerce solution residing on a Web farm needs to submit orders to a back-end Enterprise Resource Planning (ERP) application that resides on different hardware and might run on a different operating system. The Microsoft Distributed Component Object Model (DCOM), a distributed object infrastructure that allows an application to invoke Component Object Model (COM) components installed on another server, has been ported to a number of non-Windows platforms. But DCOM has never gained wide acceptance on these platforms, so it is rarely used to facilitate communication between Windows and non-Windows computers. ERP software vendors often create components for the Windows platform that communicate with the back-end system via a proprietary protocol. Some services related to application For example, if the e-commerce application accepts credit card payment for goods purchased by the customer, it must elicit the

services of the merchant bank to process the customer's credit card information. But for all practical purposes, DCOM and related technologies such as CORBA and Java RMI are limited to applications and components installed within the corporate datacenter. Two primary reasons for this are that by default these technologies leverage proprietary protocols and these protocols are inherently connection oriented. Interoperability, The remote service must be able to be consumed by clients on other platforms. Internet friendliness, The solution should work well for supporting clients that access the remote service from the Internet. Strongly typed interfaces, There should be no ambiguity about the type of data sent to and received from a remote service. Ability to leverage existing Internet standards Support for any language Support for any distributed component infrastructure, The solution should not be tightly coupled to a particular component infrastructure. In fact, you shouldn't be required to purchase, install, or maintain a distributed object infrastructure just to build a new remote service or consume an existing service. The underlying protocols should facilitate a base level of communication between existing distributed object infrastructures such as DCOM and CORBA.

CHARACTERISTIC OF WEB SERVICES


1. XML-based XML based is totally platform independent and run on any operating system and also language independent. 2. Loosely Coupled Loosely coupled means consumer of a web service does not tied web services directly. A tightly coupled system implies that the client and server logic are closely tied to one another. 3. Coarse-grained Its provide Coarse-grained facility for JAVA programs and methods. 4. Ability to be synchronous or asynchronous Synchronicity provide the facility to binding the client when client want to execute the Web Services. Means client synchronously used the services. Asynchronous operations allowed the client a client to invoke the web service when client want to execute other functions. 5. Supports to Remote Procedure Calls (RPCs) Web services support the remote procedure calls when transaction occur during exchange of documents. 6. Supports document exchange

Web services support the transfer the exchange of documents to utilize business transaction. Exchange of document totally XML based. 7. Machine-to-machine interactions Provide Machine to machine interaction through different web services component. 8. Interoperability Interoperability provide system to system work without any external effort. 9. Platform, operating system and language-independence Web services are run on any platform and there is no dependency for any language. We use this for any operating system. 10. Leveraging the architecture of the World Wide Web

WEB SERVICES COMPONENT


All the standard Web Services works using following components SOAP (Simple Object Access Protocol) UDDI (Universal Description, Discovery and Integration) WSDL (Web Services Description Language) All these components have been discussed in Web Services Architecture section.

XML-RPC
XML-RPC is the easiest way to get started with web services and simplest XML based protocol for exchanging information between computers. XML-RPC is a simple protocol that uses XML messages to perform RPCs, requests are encoded in XML and sent via HTTP POST. All XML responses are platform-independent and embedded in the body of the HTTP response and also diverse applications to communicate. A Java client can speak XML-RPC to a Perl server.

SOAP
SOAP is a simple and extensible communication protocol for exchanging information between computers and for communication between applications. It is a format for sending messages and designed to communicate via Internet. SOAP is platform independent and language independent. It allows you to get around firewalls and developed as a W3C standard.

WSDL
WSDL is an XML-based language, pronounced as 'wiz-dull' and spelled out as 'W-S-D-L', for describing Web services and how to access them. WSDL stands for Web Services

Description Language. WSDL is an XML based protocol is the standard format for describing a web service for information exchange in decentralized and distributed environments. WSDL is an integral part of UDDI, an XML-based worldwide business registry definition describes how to access a web service and what operations it will perform.

UDDI
UDDI is platform independent, open framework XML-based standard for describing, publishing, and finding Web services and stands for Universal Description, Discovery and Integration. UDDI can communicate via SOAP, CORBA, and Java RMI Protocol and uses WSDL to describe interfaces to web services. UDDI is seen with SOAP and WSDL as one of the three foundation standards of web services.

WEB SERVICES ARCHITECTURE

Service provider The service provider provide the service and implements the service. It make the service available on the internet. Service requestor This is any consumer of the web service. The requestor utilizes an existing web service by opening a network connection and sending an XML request. Service registry

Centralized directory of services. It is logically registry provides a central place. At that place developers published new services and find existing services. Service transport Service transport is responsible for transporting messages between applications. Its includes hypertext transfer protocol (HTTP), Simple Mail Transfer Protocol (SMTP), file transfer protocol (FTP). Its include something newer protocol named Blocks Extensible Exchange Protocol (BEEP). XML messaging Responsible for encoding messages in a common XML format because that messages must be understandable at the second end. Currently, this layer includes XML-RPC and SOAP. Service description Responsible for describing the public interface to a specific web service. Currently, service description is handled via the Web Service Description Language (WSDL). Service discovery Responsible for centralizing services into a common registry. Its provide easy publish and find functionality for the developer. Currently, service discovery is handled via Universal Description, Discovery, and Integration (UDDI).

Web Services Flow

SYSTEM REQUIREMENTS

Components

Requirements Enterprise Architect, Enterprise Visual Studio Developer, Professional, or Academic Edition Processor Pentium III class, 600 MHz or faster 128 MB or more for Windows 2000 or RAM Windows XP Professional and 256 MB or more for Windows .NET Server 500 MB on the system drive and 3 GB Hard disk on the installation drive Windows .NET Server, Windows XP, Operating system Windows 2000, or Windows NT 4.0 CD-ROM or DVDRequired ROM drive Microsoft mouse or compatible pointing Mouse device Video 800x600 high color (16-bit or higher)

XML-RPC
RPC RPC is a older technology stands for Remote Procedure Call. RPC is a mechanism to call function or procedure that are available on a remote computer. RPC provides a mechanism to the developer and define interfaces which must be called over a network. These interfaces can be as simple as a single function call. Introduction to XML-RPC XML-RPC provide facility to computer to call procedure from other remote computer and make function across network. XML-RPC uses the HTTP protocol to transfer information between a client computer and a server computer. It uses XML vocabulary to describe nature of request and response. XML-RPC client specified only a procedure name and parameters and the server returns fault or response to the client but both are in XML format. With XML-RPC and web services, however, the Web becomes a collection of procedural connections where computers exchange information along tightly bound paths.

Why XML-RPC ? If you want to establish communication easily between client and server, XML-RPC be the better way. It integrate multiple or more computing environment easily without sharing complex data structure. XML-RPC make easy to share information or program in a single computing environment. XML-RPC uses standers XML vocabulary to response and request. XML-RPC Data Model XML-RPC simple types mapped onto .NET data types XML-RPC simple types are mapped to and from the following .NET types: <double> <base64> <boolean> <string> <i4>or<int> System.Double System.Byte[] System.Boolean true (1) or false (0) XML-RPC.NET always outputs the System.String <string> element instead of just a <value> element with text content XML-RPC.NET by default outputs System.Int32 <i4> 64-bit floating-point numbers

<dateTime.iso8601> System.DateTim Dates in ISO8601 format: e CCYYMMDDTHH:MM:SS <i8> System.Int64 Extension to XML-RPC. The given basics types are always enclosed in a value elements. Strings may be enclosed in a value element but omit the string element. These basic types may be combined into two more complex types, arrays and structs. Arrays represent sequential information, while structs represent name-value pairs, much like hashtables, associative arrays, or properties.

<value><array><data> <value><string>Hello </string></value> <value><string>Good </string></value> </data></array></value> .......................................................

<value><array><data> <value><int>7</int></value> <value><int>124</int></value> </data></array> ....................................................... <value><array> <data> <value><boolean>1</boolean></value> <value><double>42.14159265</double></valu e> </data></array></value> XML-RPC Request Format It is a combination of HTTP headers and XML contents The XML content used the data type structure which help to passed parameter according when you call procedure and it also contains additional information about calling procedure The HTTP headers provide a wrapper for request to passing over the Web. Request contained at least single XML document, whose root element is a methodCall element Each methodCall element contains two element first one is the methodName and second element is a params element The methodName element identifies the name of the procedure to be called The params element contains a list of parameters and their values

<?xml version="1.0"?> <methodCall> <methodName>AreaSquare</methodName > <params><param> <value><double>2</double></valu e> </param></params> </methodCall> XML-RPC Response Format XML-RPC responses nearly as like request. The procedure was executed correctly and returned appropriate results are totally based on responces. If response returned a value then application may be error free. XML-RPC responses contain following information An XML-RPC response contain only one parameter. That parameter may be any type. It may be array type, struct type etc. Therefore it returns multiple values It also return boolean values.

<?xml version="1.0"?> <methodResponse>

<params><param> <value><double>4</double></v alue> </param></params> </methodResponse> XML-RPC Fault Format XML-RPC Fault is a type of responses, they contained: A fault will also have an error code which make easy to understand that what type error If any problem to processing requests then methodResponse element contain fault element instead of a params element Fault element contain a single value like a params element that indicates that something wrong

<?xml version="1.0"?> <methodResponse> <fault> <value><string>No Method</string></value> </fault> </methodResponse> .......................................................... <?xml version="1.0"?> <methodResponse> <fault><value><struct> <member> <name>name</name> <value><int>26</int></value></membe r> <member> <name>message</name> <value><string>No Method</string></value> </member></struct></value></fault> </methodResponse> XML-RPC Examples (in .net) XML-RPC Client First create client code for calling XML-RPC servers. Interface representing the XML-RPC end-point and then use the XmlRpcProxyGen class to automatically generate the code for the proxy. [XmlRpcUrl("http://...")] public interface IcityName : IXmlRpcProxy {

")] }

[XmlRpcMethod("examples.cityName string GetCityName(int cityNumber);

The proxy instance is generated using static method Create of the XmlRpcProxyGen class ICityName proxycity = XmlRpcProxyGen.Create<ICityName>(); The method on the proxy can then be called to make the XML-RPC request to the serve string cityName = proxycity.GetCityName(45); XML-RPC Services The model for XML-RPC Services are SOAP-based Web Services implemented as part of ASP. Net and they running in Microsoft IIS web server environment . An XML-RPC Service is implemented in any language that compiled under CLR (Common Language Runtime). It is create by creating a class which derives from the XmlRpcService base class. Decorating the methods to be exposed via XML-RPC with the XmlRpcMethod attribute. For example: public class CityNameService : XmlRpcService { [XmlRpcMethod("examples.getCityName", Description="Return name of city given its number")] public string getCityName(int cityNum) { if (cityNum == 45) return "Delhi"; else return "Unknown"; } } As well as specifying an XML-RPC method the XmlRpcMethod attribute is here used to specify that the method is to be called using the XML-RPC protocol as "examples.getCityName", not the name of the method used in the Service class. Alternatively the service class may also derive from an interface which defines the XML-RPC methods. The interface can then be also used to generate a proxy class as described above. For example: public interface ICityName {

[XmlRpcMethod("examples.getCityName")] string GetCityName(int cityNumber); } public interface ICityNameProxy : ICityName, IXmlRpcProxy { } public class CityNameService : XmlRpcService, ICityName { public string getCityName(int cityNum) { if (cityNum == 45) return "Delhi"; else return "Unknown"; } } 1. A class may implemented many XML-RPC methods not like a single as shown in above example. 2. The resulting assembly DLL placed in the bin directory of an IIS file directory 3. To dispatch HTTP requests to the custom handler implemented by class XmlRpcService. 4. A web.config file is used. For example, if r4r.com has a file directory called xmlrpc and the following config file is placed in the root directory of xmlrpc: <configuration> <system.web> <httpHandlers> <add verb="*" path="cityname.rem" type="r4r.CityNameService, CityNameService" /> </httpHandlers> </system.web> </configuration> The Service can be invoked via the XML-RPC protocol at this URL: http://localhost/xmlrpc/cityname.rem

SOAP (Simple Object Access Protocol)


Introduction SOAP is a W3C recommendation. SOAP is an XML-based protocol for exchanging information between computers. SOAP is acronym for Simple Object Access Protocol. Soap provide data transport layer for web services which designed for communication through internet means we can say that SOAP is a communication protocol. It is a platform independent and can be

used for broadcasting a message. SOAP is language independent and it can be exchange complete documents. SOAP enables client applications to easily connect to remote services and invoke remote methods. Other frameworks like CORBA, DCOM, and Java RMI, provide similar functionality but SOAP messages are written in XML. Why SOAP To develop any application over internet, communication is necessary. Today's applications communicate using Remote Procedure Calls (RPC) but RPC represents security problem; firewalls and proxy servers will block this kind of traffic. The communication establish between objects, like DCOM and CORBA, but one problem occurring that HTTP was not designed for that types communications. A better way to communicate between applications is over HTTP, because HTTP is supported by all Internet browsers and servers. SOAP provides facility to communicate between applications running on different operating systems, with different technologies and programming languages. A SOAP message is a XML document containing the following elements Envelope: (Mandatory) defines the start and the end of the message. Header: (Optional) Contains any optional attributes of the message used in processing the message, either at an intermediary point or at the ultimate end point. Body: (Mandatory) Contains the XML data comprising the message being sent. Fault: (Optional) An optional Fault element that provides information about errors that occurred while processing the message.

Syntax for SOAP <?xml version="1.0"?> <soap:Envelope xmlns:soap="" soap:encodingStyle=""> <soap:Header> ... </soap:Header> <soap:Body> ... <soap:Fault> ... </soap:Fault> </soap:Body> </soap:Envelope> SOAP Envelope Element The SOAP envelope indicates the start and the end of the message. SOAP envelope as a packaging mechanism and its solves the problem to knowing when receiving a message with message are ready to process it. <?xml version="1.0"?> <soap:Envelope

xmlns:soap="" soap:encodingStyle=""> ... Information Message ... </soap:Envelope> Some Features are: Envelope element is mandatory part of SOAP message and SOAP message has a root Envelop element Soap Message Envelope element contained exactly one Body element. It is necessary. When Envelope contains a Header element then it must contain no more than one. In that case it must appear as the first child of the Envelope, before the Body. SOAP versions change as well as envelop be changed. The optional SOAP encoding is also specified using a namespace name and the optional encodingStyle element, which could also point to an encoding style other than the SOAP one.

SOAP Header Element The Header element can be used to specify a digital signature for password-protected services; likewise, it can be used to specify an account number for pay-per-use SOAP services. Header elements are optional part of SOAP messages and it can occur multiple times. Headers are intended to add new features and functionality and it is the first immediate child element of the SOAP envelope. If in a SOAP message more than one header is defined then all immediate child elements of the SOAP header are interpreted as SOAP header blocks.

<soap:Header> <m:Trans xmlns:m="http://www.r4r.co.in/" soap:mustUnderstand="1">.... </m:Trans> </soap:Header> SOAP Header element can have following two attributes: Actor attribute: The SOAP protocol defines a message path as a list of SOAP service nodes. Each of these intermediate nodes can perform some processing and then forward the message to the next node in the chain. By setting the Actor attribute, the client can specify the recipient of the SOAP header. MustUnderstand attribute: This attribute indicate that a Header element is optional or mandatory.

SOAP Body Element

The SOAP body is a mandatory element which contains the application-defined XML data being exchanged in the SOAP message. The body must be contained within the envelope and must follow any headers that might be defined for the message. The body is defined as a child element of the envelope, and the semantics for the body are defined in the associated SOAP schema. <soap:Body> <m:GetPrice xmlns:m="http://www.r4r.co.in/"> <m:Item>Tables</m:Item> </m:GetPrice> </soap:Body> SOAP Fault Element SOAP fault element is in the body of the message when an error occurs during processing the response to a SOAP message. The fault is returned to the sender of the SOAP message. Its use the fault mechanism to return specific information about error. It is important to know that SOAP message can carry only one fault block It is the optional part of SOAP message. The SOAP Fault element has the following sub elements Description A text code used to indicate and identify the a class of <faultCode> errors. <faultString> Explanation of the fault in human readable format. A text string indicating that who caused the fault, a node <faultActor> that does not act as the ultimate destination must include a faultActor element. An element used to carry application-specific error messages. The detail element can contain child elements, <detail> called detail entries Sub Element

The SOAP Fault Codes Description Found an invalid namespace for the SOAP Envelope VersionMismatch element An immediate child element of the Header element, with MustUnderstand the mustUnderstand attribute set to "1", was not understood Client The message was incorrectly formed or contained Error

incorrect information :Server There was a problem with the server so the message could not proceed

SOAP Encoding SOAP includes a built-in set of rules for encoding data types. This enables the SOAP message to indicate specific data types, such as integers, floats, doubles, or arrays. SOAP data types are divided into two categories: 1. Scalar Types: Scalar types contain exactly one value for example last name, price. Simple Type boolean float Example true, false, 1, 0 -INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN -INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN -1.23, 0, 123.4, 1000.00 100010 -126789, -1, 0, 1, 126789 -126789, -1, 0 -126789, -1 -1, 12678967543233 -1, 126789675 -1, 12678 -1, 126

double decimal binary integer nonPositiveIntege negativeInteger long int short byte

nonNegativeInteger0, 1, 126789 unsignedLong unsignedInt unsignedShort 0, 12678967543233 0, 1267896754 0, 12678

unsignedByte positiveInteger date time

0, 126 1, 126789 1999-05-31, ---05 13:20:00.000, 13:20:00.000-05:00

2. Compound Types: Compound types contain multiple values, such as a purchase order or a list of stock quotes. Compound types are further subdivided into arrays and structs. Array: SOAP arrays have a very specific set of rules, means you must require to specified both the element type and size of array. It also supports multidimensional arrays. One thing is important to know that all SOAP implementations not support multidimensional functionality. To create an array, you must specify it: 1. Type of Array. 2. The array must also include an arrayType attribute. This attribute is required to specify the data type for the contained elements and the dimension of the array. Structs: Structs contain multiple values, but each element is specified with a unique accessor element. SOAP and HTTP SOAP is not tied to any one transport protocol. SOAP can be transported via SMTP, FTP or Microsoft Message Queuing (MSMQ). SOAP used HTTP request to send SOAP request. SOAP responses are returned within the content of the HTTP response. Means SOAP specification includes details on HTTP only. HTTP requests and HTTP responses both are required to set their content type to text/xml. The SOAP specification mandates that the client must provide a SOAPAction header, but the actual value of the SOAPAction header is dependent on the SOAP server implementation.

SOAP Implementations Here are some popular and widely Links available.

Apache SOAP Microsoft SOAP ToolKit 2.0 SOAP::Lite for Perl

UDDI (Universal Description, Discovery and Integration)

Introduction UDDI (Universal Description, Discovery and Integration) is a directory for storing information about web services to discovering, publishing and finding businesses and integrating business services by using the Internet. It is platform-independent framework for describing services. UDDI communicates via SOAP, CORBA and Java RMI Protocol. UDDI web service interfaces described by WSDL. UDDI is built into the Microsoft .NET platform. UDDI is an open industry initiative enabling businesses to discover each other and define how they interact over the Internet. UDDI has two parts: A registry of all a web service's metadata including a pointer to the WSDL description of a service A set of WSDL port type definitions for manipulating and searching that registry

History of UDDI In September 2000 Microsoft, IBM, and Ariba announced UDDI 1.0. Some time later other companies more than 300 (Dell, Fujitsu, HP, Hitachi, IBM, Intel, Microsoft, Oracle, SAP, and Sun) announced UDDI. May 2001, Microsoft and IBM launched the first UDDI operator sites and turned the UDDI registry live. UDDI 2.0 version announced in June 2001.At this time UDDI is sponsored by OASIS. UDDI Elements Any company can register three types of information into a UDDI registry. These three elements are: 1. White pages It include basic information which is related to the company and its business

Business name, address, contact phone number and basic information about company To allowed others to discover your web service, a unique identifiers for the company tax IDs is necessary which based upon your business identification

2. Yellow pages It include more details about the company for example the kind of electronic capabilities the company on this basis company offer to anyone to do business with it It accepted the company on there industry type like industry categorization , product codes, business identification codes and industry code which make to easier for companies to search through the listings and find exactly what they want

3. Green pages It include the technical information about a web service that make helps someone to allowed bind customer to the Web service when he has been found The various interfaces The URL locations Discovery information To find and run the Web service.

UDDI Technical Architecture [1] UDDI data model UDDI includes an XML Schema that describes five data structures: businessEntity businessService bindingTemplate tModel publisherAssertion

[2] UDDI API Specification A Specification of API for searching and publishing UDDI data. The specifications include: UDDI Replication: Its describe the data replication processes and also describe the interfaces. These interfaces are registry operator to conform achieving data replication among sites. UDDI Operators: This document outlines the behavior and operational parameters. UDDI Programmer's API: This specification inquiring about services hosted in a registry. UDDI Data Structures: Specification of XML structures contained within the SOAP messages.

UDDI Interfaces 1. The Publisher Interface The Publisher interface defines sixteen operations for a service provider managing its entries in the UDDI registry: get_authToken discard_authToken save_business save_service save_binding save_tModel delete_business delete_service delete_binding delete_tModel get_registeredInfo set_publisherAssertions add_publisherAssertions delete_publisherAssertions get_assertionStatusReport get_publisherAssertions

2. The Inquiry Interface The inquiry interface defines ten operations for searching the UDDI registry and retrieving details about specific registrations: find_binding find_business find_ltservice find_tModel

get_bindingDetail get_businessDetail get_businessDetailExt get_serviceDetail get_tModelDetail find_relatedBusinesses

UDDI Benefits It provide facility to discover the accurate business which you want from the millions business available on the internet or word wide. Most important thing is that to reach new customers and easily access to current customers. It help to expand offering and how to enable the commerce on your preferred business. Describing the web services and business processes programmatically in open environment and also in single environment. Solving customer-driven need to remove barriers to allow for rapid participation in the global Internet economy UDDI Implementations Java Implementations:

UDDI4J (UDDI for Java) jUDDI

Perl Implementation:

UDDI::Lite

Ruby Implementation:

UDDI4r

Python Implementation:

UDDI4Py

WSDL (Web Services Description Language)


Introduction WSDL is an XML based protocol and a language that UDDI uses WSDL developed jointly by Microsoft and IBM WSDL describes that what operations will performed when client accessing web service It exchanges the information in decentralized environment It exchanges the information in distributed environment It used as a combination with SOAP and XML Schema to provide web services over the Internet

Structure of the WSDL Document <definitions> <types> definition of types........ </types> <message> definition of a message.... </message> <portType> <operation> definition of a operation.. </operation> </portType> <binding> definition of a binding.... </binding> <service> definition of a service.... </service> </definitions> WSDL Elements Three major elements of WSDL that can be defined separately and they are: Types Operations Binding

Following are the elements of WSDL document: 1. Definition <definition> element is define the name of web service, it is la root element for any web services. It declares the namespaces. It is like a container for the other elements of the document. <definitions name="ServiceName.." targetNamespace="..." xmlns=".." xmlns:soap="..." xmlns:tns="..." xmlns:xsd="..."> ........................... </definitions> 2. Types Every application needed to define its inputs and outputs in and out of there domain for that one element necessary to care of defining Data types. In case of web services WSDL <types> element take responsibility to defining data types. The types are XML documents, or document parts. WSDL allowed the types to defined in separate elements in the document that provide benefit to use this types are with multiple Web services.

<types> <schema targetNamespace="" xmlns=""> <element name="Request"> <complexType><all> <element name="request1" type="string"/> </all></complexType> </element> </schema> </types> 3. Message Between the Web service providers and consumers the data being exchanged described by <message> element. Each Web Service has two messages: Input, describe parameter of web services Output, describe return data of web services

<message name="sss"> <part name="sss1" type=".."/>

</message> <message name="rrr"> <part name="ggg" type=""/> </message> For each parameter of the Web Service's function defined it may be zero or for more <part> parameter. For all associates with a concrete type defined in the <types> container element. 4. Port type The <portType> element combines multiple message elements and mapped to multiple transports through various bindings. We can say that a it provide a complete one way or round-trip operation. A <portType> can combine one request and one response message into a single request/response operation. The <portType> element commonly used in SOAP services. <portType name="name"> <operation name="sayHello"> <input message=""/> <output message=""/> </operation> </portType> 5. Binding HTTP GET, HTTP POST, or SOAP and other transport make binding easily available. The <binding> element provide that how the portType operation transmitted over the network. It provide concrete information about the protocols that is used for the transaction. Binding also provide information that where service uploaded. <binding name="" type=""> 6. Port A <port> element defines an individual endpoint by specifying a single address for a binding. Port be the restricted to specify more than one address information. It must be binding the address information. The port element has two attributes 1. 2. The name attribute: It provide unique name among all port. The binding attribute: The binding attribute banded the linking rules that defined by the WSDL.

7. Service

The <service> element defined the ports and is a collection of port which supported by the Web service. There is only one port element for each protocol which supported the web services. It include the documentation element that provide the Human readable Documentation. <service name="Name"> <documentation>Hello</documentati on> <port binding="" name=""> <soap:address location=""> </port> </service> In addition to these major elements, the WSDL specification also defines the following utility elements: Documentation: This element is used to provide Human readable document Import: Its import the WSDL document.

Advantage and Disadvantage


Advantages Interoperability: Most important benefit of Web services, its work outside of private networks and offering developers to find their solutions in appropriate way. Its provide Interoperability between many software's running ion different platform. Web Services are filely platform-independent Reusability: Web services use open standards and protocols. Deployment of services possible easily because they are not a component-based model of application for development. This makes it easy to reuse Web Service components as appropriate in other services. Deploy ability: Web services deploy over the Web and any user use this without any independent and mapping problems. Usability: Web services allow the reuse of services and components within an infrastructure. Web Services allow the business logic of different platform and exposed it over the Internet. This thigh provide the facility to use web services any where for different platform.

Disadvantage Web services suffered poor performance in comparison other distributed application RMI, CORBA, or DCOM. XML explicitly does not count among its design goals either conciseness of encoding or efficiency of parsing. Transaction in Web Services is not infancy like other distributed standards like CORBA. The web service transaction is nonexistent. When client make a request to the server. When the server response at that time if power gone and client end crash, in this condition server never known that client not activated.

How To make a Web Services ( To Calculate Circle area using C#)


Step 1. Start a New Web Site

Click on ASP.Net Web Services and named your service CircleArea and press on OK Step 2. The code written for your application which return area of circle (Service.cs). This service contain a CircleArea method which calculate the area. using System; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Linq; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService { public Service () { } [WebMethod (Description="To calculate Area of Circle")] public double CircleArea(int a) {return 3.14 * (a * a);} } Step 3. Run your service.

Click on CircleArea. Service is run and when you input value the result be shown.

If you want to see Service Description. Click on Service Description

Now Web service is Created. 1. If you want to know how to Use this service in Your ASP.Net Application

Click

Here.
2.

Click Here how to use in Console Application.

Create a Web Service For Calculate Age when user input Date Step 1. Open a new Web Site and click on ASP.Net Web Services press on OK as shown below in fig.

Step 2. The code (Service.cs) written for Calculating Age , Calculate Factorial and Square Root of a Number. using System; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Linq; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService {[WebMethod (Description="Calculating Age")] public string calAge(DateTime date) { DateTime nowDate = System.DateTime.Now; System.TimeSpan span = nowDate - date; int days = (int)span.TotalDays; int yea = days / 365; string age = yea.ToString() + " years "; return age;} [WebMethod(Description = "Calculating

SquareRoot")] public double calSquareRoot(int a) { double i = 0; double x1, x2=0; while ((i * i) <= a) i += 0.1; x1 = i; for (int j = 0; j < 10; j++) { x2 = a; x2 /= x1; x2 += x1; x2 /= 2; x1 = x2;} return x2;} [WebMethod(Description = "Calculating Factorial")] public double calFactorial(int a) {if (a == 0)return 1; else return (a*calFactorial(a-1));}} Step 3. Debug The service

Click on each link and check your service Step 4. To use this service, go to your project solution right click and click on Add Web Reference. A new window open

Copy the URL of your running web service and paste it in the new window place as shown in below fig.

Note: Remember the web reference name, it will be added in your project (.cs ) file e.g. this reference help to call the method of your web services. You will call the methods to create an object of SERVICE. To know more click Here using localhost; Click on Add Reference, The service will be added in your web site. It will be show on your page like below fig.

How to Use web Services in ASP. Net using C#


Step 1. Run Your Service and open a new Website, Add a label and one textBox to enter radius of Circle

Click on Add web Reference

Copy the URL of Your running web Service and paste it in Your Web Reference window

Click on Go Step 2. You can change your Web reference name but you remember this. click on add Reference

The service will be added in your application

Step 3. Now add the Web reference (name space) in your application (shown below). written the following code in your .cs file (Default.aspx.cs). using System; using System.Configuration; using System.Web; using System.Data; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using localhost; public partial class _Default : System.Web.UI.Page { Service ser = new Service(); protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { double area = ser.CircleArea(int.Parse(TextBox1.Text)); Label2.Text = "Area is : " + area.ToString(); } } Step 4. Run your application (Necessary to running your web service which you use in your application)

How to Use web Services in Console Application using C#


Step 1. Open a new project and select console Application. press on Ok.

Step 2. Click on Add service reference a new window open Click on Advance,

A new window open click on Add Web reference and copy the URL of your running service and paste it to the URL space in new window shown below and click on Go. Click on Add reference but remember your Web reference name

The Service will be added in your project

Step 3. Written the following code in your Program (Program.cs) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; namespace Circlearea { class Program { static void Main(string[] args) { localhost.Service lo = new localhost.Service(); Console.Write("Please enter the value="); int area = Convert.ToInt32(Console.ReadLine()); double fr=lo.CircleArea(area); Console.WriteLine("Area is =" + fr); Console.ReadLine(); } } } Step 4. Run the Application

Webservice Interview Questions And Answers

Page 1
Ques: 1 What is a Web service? Ans: Web service is like software that makes it available over the Internet. Web Services using the standardized XML messaging system. The Client invoke a message to use a Web Service and send a request to the server In XML formate and server response to the client in XML file formate. Web services are Platform independent and it accessed by any application developed in any Language. Ques: 2 What is SOAP? Ans: SOAP stands for Simple Object Access Protocol and it is a protocol which exchange information between computer. Total transaction is the XML based and it is Platform independent. We can say that it is a variety of messaging to system and communicate via transport protocol. Ques: 3 What is WSDL? Ans: WSDL stands for Web Services Description Language and its represent a layer within a web service protocol stack. WSDL containing the Data types for all XML messages and it provide information about all XML messages. WSDL provide the address information of the locating services. Ques: 4 What is the .net web Services? Ans: Web service is like a component which share the the information over internet and make easy to develop application as your required services. ASP .net provide the facility to make a web method means which functioning you applied in your service. The client when accessing service the request of client in XMl formate and the inputed value passed as a parameter for that Web Method, the server response also in XML formate. One thing is necessary that services already running over the Internet. Ques: 5 What is UDDI ? Ans: UDDI (Universal Description, Discovery and Integration) is a directory for storing information about web services to discovering, publishing and finding businesses and integrating business services by using the Internet. It is platform-independent framework for describing services. UDDI communicates via SOAP, CORBA and Java RMI Protocol. UDDI web service interfaces described by WSDL. UDDI is built into the Microsoft .NET platform. UDDI is an open industry initiative enabling businesses to discover each other and define how they interact over the Internet. Ques: 6 Describe the something about UDDI elements ? Ans: These three elements are:

1. White pages: It include basic information which is related to the company and its business and allowed others to discover your web service in unique identifier. 2. Yellow pages: It include more details about the company for example the kind of electronic capabilities the company on this basis company offer to anyone to do business with it. 3. Green pages: It include the technical information about a web service that make helps someone to allowed bind customer to the Web service when he has been found. Ques: 7 What do you mean by XML-RPC ? Ans: RPC is a older technology stands for Remote Procedure Call. RPC is a mechanism to call function or procedure that are available on a remote computer. XML-RPC provide facility to computer to call procedure from other remote computer and make function across network. XML-RPC uses the HTTP protocol to transfer information between a client computer and a server computer. It uses XML vocabulary to describe nature of request and response. XML-RPC client specified only a procedure name and parameters and the server returns fault or response to the client but both are in XML format, with XMLRPC and web services, however, the Web becomes a collection of procedural connections where computers exchange information along tightly bound paths. Ques: 8 Why use web services. Give some reasons in brief ? Ans: 1. Component-based programming has become more popular For example end-to-end e-commerce solution residing on a Web farm needs to submit orders to a backend Enterprise Resource Planning (ERP) application that resides on different hardware and might run on a different operating system. The Microsoft Distributed Component Object Model (DCOM), a distributed object infrastructure that allows an application to invoke Component Object Model (COM) components installed on another server, has been ported to a number of non-Windows platforms. But DCOM has never gained wide acceptance on these platforms, so it is rarely used to facilitate communication between Windows and non-Windows computers. ERP software vendors often create components for the Windows platform that communicate with the back-end system via a proprietary protocol. 2. Some services related to application For example, if the e-commerce application accepts credit card payment for goods purchased by the customer, it must elicit the services of the merchant bank to process the customer's credit card information. But for all practical purposes, DCOM and related technologies such as CORBA and Java RMI are limited to applications and components installed within the corporate datacenter. Two primary reasons for this are that by default these technologies leverage proprietary protocols and these protocols are inherently connection oriented. 3. Interoperability, The remote service must be able to be consumed by clients on other platforms. 4. Internet friendliness, The solution should work well for supporting clients that access the remote service from the Internet. 5. Strongly typed interfaces, There should be no ambiguity about the type of data sent to and received from a remote service. Ques: 9 Advantages of Web Services ? Ans: 1. Interoperability: Most important benefit of Web services, its work outside of private networks and offering developers to find their solutions in appropriate way. Its provide Interoperability between many software's running ion different platform. Web Services are virtually platformindependent

2. Reusability: Web services use open standards and protocols. Deployment of services possible easily because they are not a component-based model of application for development. This makes it easy to reuse Web Service components as appropriate in other services. 3. Deploy ability: Web services deploy over the Web and any user use this without any independent and mapping problems. 4. Usability: Web services allow the reuse of services and components within an infrastructure. Web Services allow the business logic of different platform and exposed it over the Internet. This thigh provide the facility to use web services any where for different platform. Ques: 10 Disadvantages of Web Services ? Ans: 1. Web services suffered poor performance in comparison other distributed application RMI, CORBA, or DCOM. 2. XML explicitly does not count among its design goals either conciseness of encoding or efficiency of parsing. 3. Transaction in Web Services is not infancy like other distributed standards like CORBA. The web service transaction is nonexistent. 4. When client make a request to the server. When the server response at that time if power gone and client end crash, in this condition server never known that client not activated. Ques: 11 Define the characteristic of web services ? Ans: 1. XML-based: XML based is totally platform independent and run on any operating system and also language independent 2. Loosely Coupled: Loosely coupled means consumer of a web service does not tied web services directly. A tightly coupled system implies that the client and server logic are closely tied to one another. 3. Coarse-grained: Its provide Coarse-grained facility for JAVA programs and methods. 4. Ability to be synchronous or asynchronous: Synchronized provide the facility to binding the client when client want to execute the Web Services. Means client synchronously used the services. Asynchronous operations allowed the client a client to invoke the web service when client want to execute other functions. 5. Supports to Remote Procedure Calls (RPCs): Web services support the remote procedure calls when transaction occur during exchange of documents. 6. Supports document exchange: Web services support the transfer the exchange of documents to utilize business transaction. Exchange of document totally XML based. 7. Interoperability provide system to system work without any external effort. Ques: 12 Give some brief idea about Web Services Architecture component ? Ans: 1. Service provider: The service provider provide the service and implements the service. It make the service available on the internet 2. Service requestor: This is any consumer of the web service. The requestor utilizes an existing web service by opening a network connection and sending an XML request. 3. Service registry: Centralized directory of services. It is logically registry provides a central place. At that place developers published new services and find existing services. 4. Service transport: Service transport is responsible for transporting messages between applications. Its includes hypertext transfer protocol (HTTP), Simple Mail Transfer Protocol (SMTP), file transfer protocol (FTP).

Its include something newer protocol named Blocks Extensible Exchange Protocol (BEEP). 5. XML messaging: Responsible for encoding messages in a common XML format because that messages must be understandable at the second end. Currently, this layer includes XML-RPC and SOAP. 6. Service description: Responsible for describing the public interface to a specific web service. Currently, service description is handled via the Web Service Description Language (WSDL). 7. Service discovery: Responsible for centralizing services into a common registry. Its provide easy publish and find functionality for the developer. Currently, service discovery is handled via Universal Description, Discovery, and Integration (UDDI).

Webservice Interview Questions And Answers

Page 1
Ques: 1 Give some brief idea about Web Services Architecture component ? Ans: 1. Service provider: The service provider provide the service and implements the service. It make the service available on the internet 2. Service requestor: This is any consumer of the web service. The requestor utilizes an existing web service by opening a network connection and sending an XML request. 3. Service registry: Centralized directory of services. It is logically registry provides a central place. At that place developers published new services and find existing services. 4. Service transport: Service transport is responsible for transporting messages between applications. Its includes hypertext transfer protocol (HTTP), Simple Mail Transfer Protocol (SMTP), file transfer protocol (FTP). Its include something newer protocol named Blocks Extensible Exchange Protocol (BEEP). 5. XML messaging: Responsible for encoding messages in a common XML format because that messages must be understandable at the second end. Currently, this layer includes XML-RPC and SOAP. 6. Service description: Responsible for describing the public interface to a specific web service. Currently, service description is handled via the Web Service Description Language (WSDL). 7. Service discovery: Responsible for centralizing services into a common registry. Its provide easy publish and find functionality for the developer. Currently, service discovery is handled via Universal Description, Discovery, and Integration (UDDI). Ques: 2 Define the characteristic of web services ? Ans: 1. XML-based: XML based is totally platform independent and run on any operating system and also language independent 2. Loosely Coupled: Loosely coupled means consumer of a web service does not tied web services directly. A tightly coupled system implies that the client and server logic are closely tied to one another. 3. Coarse-grained: Its provide Coarse-grained facility for JAVA programs and methods. 4. Ability to be synchronous or asynchronous: Synchronized provide the facility to binding the client when client want to execute the Web Services. Means client synchronously used the services. Asynchronous operations

allowed the client a client to invoke the web service when client want to execute other functions. 5. Supports to Remote Procedure Calls (RPCs): Web services support the remote procedure calls when transaction occur during exchange of documents. 6. Supports document exchange: Web services support the transfer the exchange of documents to utilize business transaction. Exchange of document totally XML based. 7. Interoperability provide system to system work without any external effort. Ques: 3 Disadvantages of Web Services ? Ans: 1. Web services suffered poor performance in comparison other distributed application RMI, CORBA, or DCOM. 2. XML explicitly does not count among its design goals either conciseness of encoding or efficiency of parsing. 3. Transaction in Web Services is not infancy like other distributed standards like CORBA. The web service transaction is nonexistent. 4. When client make a request to the server. When the server response at that time if power gone and client end crash, in this condition server never known that client not activated. Ques: 4 Advantages of Web Services ? Ans: 1. Interoperability: Most important benefit of Web services, its work outside of private networks and offering developers to find their solutions in appropriate way. Its provide Interoperability between many software's running ion different platform. Web Services are virtually platformindependent 2. Reusability: Web services use open standards and protocols. Deployment of services possible easily because they are not a component-based model of application for development. This makes it easy to reuse Web Service components as appropriate in other services. 3. Deploy ability: Web services deploy over the Web and any user use this without any independent and mapping problems. 4. Usability: Web services allow the reuse of services and components within an infrastructure. Web Services allow the business logic of different platform and exposed it over the Internet. This thigh provide the facility to use web services any where for different platform. Ques: 5 Why use web services. Give some reasons in brief ? Ans: 1. Component-based programming has become more popular For example end-to-end e-commerce solution residing on a Web farm needs to submit orders to a backend Enterprise Resource Planning (ERP) application that resides on different hardware and might run on a different operating system. The Microsoft Distributed Component Object Model (DCOM), a distributed object infrastructure that allows an application to invoke Component Object Model (COM) components installed on another server, has been ported to a number of non-Windows platforms. But DCOM has never gained wide acceptance on these platforms, so it is rarely used to facilitate communication between Windows and non-Windows computers. ERP software vendors often create components for the Windows platform that communicate with the back-end system via a proprietary protocol. 2. Some services related to application For example, if the e-commerce application accepts credit card payment for goods purchased by the customer, it must elicit the services of the merchant bank to process the customer's credit card information. But for all practical purposes, DCOM and related

technologies such as CORBA and Java RMI are limited to applications and components installed within the corporate datacenter. Two primary reasons for this are that by default these technologies leverage proprietary protocols and these protocols are inherently connection oriented. 3. Interoperability, The remote service must be able to be consumed by clients on other platforms. 4. Internet friendliness, The solution should work well for supporting clients that access the remote service from the Internet. 5. Strongly typed interfaces, There should be no ambiguity about the type of data sent to and received from a remote service. Ques: 6 What do you mean by XML-RPC ? Ans: RPC is a older technology stands for Remote Procedure Call. RPC is a mechanism to call function or procedure that are available on a remote computer. XML-RPC provide facility to computer to call procedure from other remote computer and make function across network. XML-RPC uses the HTTP protocol to transfer information between a client computer and a server computer. It uses XML vocabulary to describe nature of request and response. XML-RPC client specified only a procedure name and parameters and the server returns fault or response to the client but both are in XML format, with XMLRPC and web services, however, the Web becomes a collection of procedural connections where computers exchange information along tightly bound paths. Ques: 7 Describe the something about UDDI elements ? Ans: These three elements are: 1. White pages: It include basic information which is related to the company and its business and allowed others to discover your web service in unique identifier. 2. Yellow pages: It include more details about the company for example the kind of electronic capabilities the company on this basis company offer to anyone to do business with it. 3. Green pages: It include the technical information about a web service that make helps someone to allowed bind customer to the Web service when he has been found. Ques: 8 What is UDDI ? Ans: UDDI (Universal Description, Discovery and Integration) is a directory for storing information about web services to discovering, publishing and finding businesses and integrating business services by using the Internet. It is platform-independent framework for describing services. UDDI communicates via SOAP, CORBA and Java RMI Protocol. UDDI web service interfaces described by WSDL. UDDI is built into the Microsoft .NET platform. UDDI is an open industry initiative enabling businesses to discover each other and define how they interact over the Internet. Ques: 9 What is the .net web Services? Ans: Web service is like a component which share the the information over internet and make easy to develop application as your required services. ASP .net provide the facility to make a web method means which functioning you applied in your service. The client when accessing service the request of client in XMl formate and the inputed value passed as a parameter for that Web Method, the server response also in XML formate. One thing is necessary that services already running over the Internet. Ques: 10 What is WSDL? Ans: WSDL stands for Web Services Description Language and its represent a layer

within a web service protocol stack. WSDL containing the Data types for all XML messages and it provide information about all XML messages. WSDL provide the address information of the locating services. Ques: 11 What is SOAP? Ans: SOAP stands for Simple Object Access Protocol and it is a protocol which exchange information between computer. Total transaction is the XML based and it is Platform independent. We can say that it is a variety of messaging to system and communicate via transport protocol. Ques: 12 What is a Web service? Ans: Web service is like software that makes it available over the Internet. Web Services using the standardized XML messaging system. The Client invoke a message to use a Web Service and send a request to the server In XML formate and server response to the client in XML file formate. Web services are Platform independent and it accessed by any application developed in any Language.

Anda mungkin juga menyukai