Presentation is loading. Please wait.

Presentation is loading. Please wait.

.NET Web Services by Akram Mohammed.

Similar presentations


Presentation on theme: ".NET Web Services by Akram Mohammed."— Presentation transcript:

1 .NET Web Services by Akram Mohammed

2 Why do we need Web Services?
What is a Web Service? Simple Architecture How does web services works? Web services platform elements 2 Types of Web services How to Create a Web Service?

3 Why do we need Web Services?
After buying something over the Internet, we may have wondered about the delivery status. Calling the delivery company consumes your time, and it's also not a value-added activity for the delivery company. To eliminate this scenario the delivery company needs to expose the delivery information without compromising its security.

4 Enterprise security architecture can be very sophisticated
Enterprise security architecture can be very sophisticated. What if we can just use port 80 (the Web server port) and expose the information through the Web server? Still, we have to build a whole new Web application to extract data from the core business applications. This will cost the delivery company money.

5 All the company wants is to expose the delivery status and at the same time concentrate on its core business. This is where Web Services come in.

6 What is a Web Service? Web Services are a very general model for building applications and can be implemented for any system that supports communication over the Internet.

7 Web Services use the best of component-based development and the Web.
Component-base object models like Distributed Component Object Model (DCOM), Remote Method Invocation (RMI), and Internet Inter-Orb Protocol (IIOP) have been around for some time. Unfortunately all these models depend on an object-model-specific protocol. Web Services extend these models a bit further to communicate with the Simple Object Access Protocol (SOAP) and Extensible Markup Language (XML) to eradicate the object-model-specific protocol barrier.

8 Web Services basically uses Hypertext Transfer Protocol (HTTP) and SOAP to make business data available on the Web. It exposes the business objects (COM objects, Java Beans, etc.) to SOAP calls over HTTP and executes remote function calls . The Web Service consumers are able to invoke method calls on remote objects by using SOAP and HTTP over the Web.

9 Simple Architecture SOAP calls are remote function calls that invoke method executions on Web Service components at Location B. The output is rendered as XML and passed back to the user at Location A.

10 How is the user at Location A aware of the semantics of the Web Service at Location B? This question is answered by conforming to a common standard. Service Description Language (SDL), SOAP Contract Language (SCL) and Network Accessible Specification Language (NASSL) are some languages built for this purpose. However, IBM and Microsoft recently agreed on the Web Service Description Language (WSDL) as the Web Service standard.

11 The structure of the Web Service components is exposed using this Web Service Description Language. WSDL 1.1 is a XML document describing the attributes and interfaces of the Web Service.

12 Web services are application components
Web services are self-contained and self-describing Web services can be discovered using UDDI Web services can be used by other applications

13 How does web services works
The basic Web services platform is XML + HTTP. XML provides a language which can be used between different platforms and programming languages and still express complex messages and functions.

14 Web services platform elements
SOAP UDDI WSDL

15 What is SOAP? SOAP is a communication protocol
SOAP is for communication between applications SOAP is a format for sending messages SOAP is designed to communicate via Internet SOAP is language independent

16 SOAP is based on XML(extensible)
SOAP allows you to get around firewalls SOAP will be developed as a W3C standard SOAP is a simple XML-based protocol that allows applications to exchange information over HTTP.

17 What is WSDL? WSDL is an XML-based language for describing Web services and how to access them. WSDL is used to describe Web services

18 WSDL is also used to locate Web services
WSDL is not yet a W3C standard WSDL is an XML-based language for describing Web services and how to access them. WSDL describes a web service, along with the message format and protocol details for the web service.

19 What is UDDI? UDDI is a directory service where businesses can register and search for Web services. UDDI is a directory for storing information about web services UDDI is a directory of web service interfaces described by WSDL UDDI communicates via SOAP UDDI is built into the Microsoft .NET platform

20 Web services can be used in two ways.
Reusable application components: There are things different 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. Ideally, there will only be one type of each application component, and anyone can use it in their application.

21 Connect existing software:
Web services help solve the interoperability problem by giving different applications a way to link their data. Using Web services you can exchange data between different applications and different platforms.

22 .NET Web service Web Services promise to bring information into your applications from the Internet in much the same way that browsers have made information available to end users. The .Net framework introduces Web Services as an integral part of the architecture, making it very easy to create and consume these services with minimal amounts of code written.

23 The core software component to implement this application will be MS
The core software component to implement this application will be MS .NET Framework SDK. You can download a version from Microsoft. The preferred Integration Development Environment (IDE) to create Web Services is Visual Studio .NET. However, you can easily use any text editor (WordPad, Notepad, Visual Studio 6.0) to create a Web Service file.

24 Basic knowledge of .NET platform
Basic knowledge of C# Basic knowledge of object-oriented concepts

25 Creating a Web Service We are going to use C# to create a Web Service called "SecurityWebService.“ The first line of the file will look like WebService Language="C#" class="SecurityWebService" %> This line will instruct the compiler to run on Web Service mode and the name of the C# class. We also need to access the Web Service namespace.

26 using System; using System.Web.Services; The SecurityWebService class should inherit the functionality of the Web Services class. public class SecurityWebService : WebService Now we can use our object-oriented programming skills to build a class. C# classes are very similar to C++ or Java classes. It will be very easy to create a C# class .

27 Dot-net Web Services are intelligent enough to cast basic data types
Dot-net Web Services are intelligent enough to cast basic data types. Therefore, if we return "int," "float," or "string" data types, it can convert them to standard XML output. Unfortunately, in most cases we need get a collection of data regarding a single entity. Let's take an example. Our SecurityWebService stock quotes service requires the user to enter a company code, and it will deliver the full company name and the current stock price.

28 Therefore, we have three pieces of information for a single company:
Company code (data type - string) Company name (data type - string) Price (data type - Double) We need to extract all this data when we are referring to a single stock quote. There are several ways of doing this. The best way could be to bundle them in an enumerated data type. We can use "structs" in C# to do this, which is very similar to C++ structs.

29 public struct SecurityInfo
{ public string Code; public string CompanyName; public double Price; } Now we have all the building blocks to create our Web Service. Therefore, our code will look like.

30 <%@ WebService Language="C#" class="SecurityWebService" %>
using System; using System.Web.Services; public struct SecurityInfo { public string Code; public string CompanyName; public double Price; } public class SecurityWebService : WebService private SecurityInfo Security; public SecurityWebService() Security.Code = ""; Security.CompanyName = ""; Security.Price = 0;

31 private void AssignValues(string Code)
{ // This is where you use your business components. // Method calls on Business components are used to populate the data. // For demonstration purposes, I will add a string to the Code and // use a random number generator to create the price feed. Security.Code = Code; Security.CompanyName = Code + " Pty Ltd"; Random RandomNumber = new System.Random(); Security.Price = double.Parse(new System.Random(RandomNumber.Next(1,10)).NextDouble().ToString("##.##")); } [WebMethod(Description="This method call will get the company name and the price for a given security code.",EnableSession=false)]

32 public SecurityInfo GetSecurityInfo(string Code)
{ AssignValues(Code); SecurityInfo SecurityDetails = new SecurityInfo(); SecurityDetails.Code = Security.Code; SecurityDetails.CompanyName = Security.CompanyName; SecurityDetails.Price = Security.Price; return SecurityDetails; }

33 Remember, this Web Service can be accessed through HTTP for any use
Remember, this Web Service can be accessed through HTTP for any use. We may be referring to sensitive business data in the code and wouldn't want it to fall into the wrong hands. The solution is to protect the business logic function and only have access to the presentation functions. This is achieved by using the keyword "[Web Method]" in C#. Let's look at the function headers of our code. [WebMethod(Description="This......",EnableSession=false)] public SecurityInfo GetSecurityInfo(string Code)

34 This function is exposed to the public
This function is exposed to the public. The "description" tag can be used to describe the Web Service functionality. Since we will not be storing any session data, we will disable the session state.

35 private void AssignValues(string Code)
This is a business logic function that should not be publicly available. We do not want our sensitive business information publicly available on the Web. (Note:- Even if you change the "private" keyword to "public," it will still not be publicly available. Why?

36 We can use the business logic in this function to get the newest stock price quote. There is added text to the company code to create the company name. The price value is generated using a random number generator.

37 We may save this file as "SampleService
We may save this file as "SampleService.asmx" under an Internet Information Service (IIS)-controlled directory. We can saved it under a virtual directory called "/work/aspx." We can bring it up on a Web browser.

38

39 THANKS


Download ppt ".NET Web Services by Akram Mohammed."

Similar presentations


Ads by Google