Web services
Upcoming SlideShare
Loading in...5
×
 

Web services

on

  • 589 views

 

Statistics

Views

Total Views
589
Views on SlideShare
589
Embed Views
0

Actions

Likes
0
Downloads
18
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Web services Web services Presentation Transcript

  •  There are things applications need very often. So why make these over and over again? Web services can offer application-components like: currency conversion, weather reports, or even language translation as services. Unlike traditional client/server models, such as a Web server/Web page system, Web services do not provide the user with a GUI. Web services instead share business logic, data and processes through a programmatic interface across a network. Developers can then add the Web service to a GUI (such as a Web page or an executable program) to offer specific functionality to users.
  • There are two primary ways to create servicesin ASP.NET. Web services based on the ASP.NET (.asmx) model. Microsoft Windows Communication Foundation (WCF) model
  • This is a familiar ASP.NET programmingexperience for services that are meant to beexclusively bound to Hypertext TransferProtocol (HTTP) and hosted by MicrosoftInternet Information Services (IIS) andASP.NET.
  •  The term Web services describes a standardized way of integrating Web-based applications using the XML, SOAP, WSDL and UDDI open standards over an Internet protocol backbone. XML is used to tag the data, SOAP is used to transfer the data, WSDL is used for describing the services available and UDDI is used for listing what services are available. Used primarily as a means for businesses to communicate with each other and with clients, Web services allow organizations to communicate data without intimate knowledge of each others IT systems
  • SOAP, originally defined as Simple Object AccessProtocol, is a protocol specification for exchangingstructured information in the implementation of WebServices in computer networks.It relies on Extensible Markup Language (XML) for itsmessage format, and usually relies on otherApplication Layer protocols, most notably HypertextTransfer Protocol (HTTP) and Simple Mail TransferProtocol (SMTP), for message negotiation andtransmission.
  •  WSDL stands for Web Services Description Language WSDL is an XML-based language for locating and describing Web services. An XML-formatted language used to describe a Web services capabilities as collections of communication endpoints capable of exchanging messages. WSDL is an integral part of UDDI, an XML- based worldwide business registry.
  • ASP.NET wrap the web service code as a proxy object. This object willknow how to expose your Web service. This includes deserializing SOAPrequests, executing your .NET Framework code, and serializing yourresponse to be sent back to the requesting client as a SOAP message.
  •  An ASP.NET XML Web service is a class you write that inherits from the class System.Web .Services.WebService. Create a Web service project through the Add New Project ->ASP.NET Web Service application. This generates a separate project for your Web service application that has a structure similar to a Web site. This includes a folder for App_Data, a Web.config file, and related elements.
  •  Like a Web page, Web services are exposed through Uniform Resource Locators (URLs). This means your domain name followed by a page name, as in http://MyDomain/MyService.asmx. Web service like a class that only exposes methods. Each Web service can expose multiple methods. The page for an XML Web service is defined by the .asmx file. This file is nothing more than a simple text file that is used as a pointer to the code of your Web service. @ WebService directive points to the actual code for the Web service.
  •  This class can be used to provide information about your Web service. This information is used by clients that wish to reference the Web service. You can provide both a namespace and a description of your Web service by applying the WebService attribute and parameters to your class. The description parameter is simply text you write to identify the high-level intent of your Web service. The namespace parameter sets the namespace of your Web service. This should be a domain name under your control. Visual Studio uses the tempuri.org namespace as filler until you define your actual namespace.
  •  You apply this attribute to any public method in your Web service class you wish to expose as part of your service. The WebMethod attribute class has a number of constructors used for various groups of parameter values. 1. enableSessionState 2. transactionOption 3. cacheDuration 4. bufferResponse You can also use the Serializable attribute class to tag class outside your Web service. This ensures any public members of the class can be serialized by ASP.NET.
  •  The first step is setting a Web reference from your Web site to the given service. You do this by right-clicking your project file and choosing Set Web Reference. This opens the Add Web Reference dialog box. Here, you define the URL of your service, select the given service (.asmx file), and set a name for the reference. This name will be used by the generated proxy class to define the namespace for accessing your service.
  •  This model allows developers to write services that can be configured to work with a variety of hosts, protocols, and clients. For example, you might want to write a service that is accessed over Transmission Control Protocol (TCP) instead of HTTP. If that same service code needed to be called over both HTTP and TCP, you had to write and host it twice. This is one of the many problems WCF is meant to solve.
  •  WCF is a unifying programming model. It is meant to define a singular way for writing services and thereby unify things like Web services (.asmx), .NET Remoting, Message Queue (MSMQ), Enterprise Services (COM+), and Web Services Enhancements (WSE). It does not replace these technologies on an individual basis. Instead, it provides a single programming model that you can use to take advantage of all of these items at once. With WCF, you can create a single service that can be exposed as HTTP, TCP, named pipes, and so on. You also have multiple hosting options.
  •  WCF Service is a program that exposes a collection of Endpoints. Each Endpoint is a portal for communicating with the world. All the WCF communications are take place through end point. End point consists of three components. Address Binding Contract
  •  Basically URL, specifies where this WCF service is hosted . Client will use this url to connect to the service. http://localhost:8090/MyService/SimpleCalcu lator.svc
  •  Binding will describes how client will communicate with service. There are different protocols available for the WCF to communicate to the Client. You can mention the protocol type based on your requirements. The following table gives some list of protocols supported by WCF binding.
  •  Collection of operation that specifies what the endpoint will communicate with outside world. Usually name of the Interface will be mentioned in the Contract, so the client application will be aware of the operations which are exposed to the client. There are multiple contract types in WCF, including service contract, operation contract, message contract, fault contract (for error handling), and data contract. These contracts work together to indicate to the client code consuming the WCF service how it should define communication messages
  •  Creating and consuming WCF services follow a standard set of programming tasks. You follow these steps every time you wish to create and consume a new WCF service: 1. Define the service contract. 2. Implement (or write) the service contract. 3. Configure a service endpoint(s). 4. Host the service in an application. 5. Reference and call the service from a client application.
  •  In WCF programming, you first define an interface and decorate that interface with a number of attributes. These WCF attribute classes are found in the System.ServiceModel namespace. These attribute classes are used to define the details of the contract that your service will have with calling clients.
  •  ServiceContract : The ServiceContract attribute class has parameters for setting things like whether the service requires a session (SessionMode), the namespace, the name of the contract, the return contract on a two-way contract (CallbackContract), and more. OperationContract : attribute class to set things like whether the contract does not return a reply (IsOneWay), the message-level security (ProtectionLevel), or whether the method supports asynchronous calls (AsyncPattern). DataContract : The DataContract attribute class is used to mark types you write (classes, enumerations, structures) DataMembers : The DataMember attribute class is used to mark individual fields and properties that you want to serialize. You use this class in conjunction with the Data-Contract class.
  •  Visual Studio and ASP.NET define the WCF Service Application project template. This template defines a Web project that serves to host the WCF service. This project contains a reference to System.ServiceModel.dll, which contains the WCF classes. Creating a new instance of this project template will also generate a default service (Service1.svc) and a related contract file IService1.vb or .cs).
  • Finally, a WCF Service application is automatically configuredto be hosted in IIS and expose a standard HTTP endpoint. Thisinformation can be found inside the <system.servicemodel>section of the Web.config file.<system.serviceModel><services> <service name="NorthwindServices.Service1" behaviorConfiguration="NorthwindServices.Service1Behavior"> <endpoint address="" binding="wsHttpBinding" contract="NorthwindServices.IService1"> <identity> <dns value="localhost"/> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/></service></services>
  • <behaviors> <serviceBehaviors> <behavior name="NorthwindServices.Service1Behavior"> <!-- to avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors></behaviors></system.serviceModel>