Unit 7 & 8 - Working With XML & Web Service SB
Unit 7 & 8 - Working With XML & Web Service SB
Web Services
UNIT - 7
XML
XML stands for eXtensible Markup Language
XML is text file that contains information organized in a
structure that meets XML standards.
XML is markup language much like HTML but both have many
differences between them.
Using XML you can create your own tags.XML is used to
describe data.
XML is platform independent.
XML offers an effective way of defining standards for data
transfer across different types of applications.
XML can seprate data from HTML.HTML is mainly used for
presentation where XML focuses on data part.
XML allows data only in well formed manner which makes
easy to identify the data even multiple lelvels.
XML
In XML, you can create DTD(Data Type Definition) and
XSD(XML Schema Definition) files to specify your own set of
rules for user defined tags.
In XML, you can create XSLT(XML Style sheet
Transformation) files to show your XML data in particular
format.
Example :
<age>35</age>
XML Parser
XML Parser is small software tool that reads XML file for two
purpose.
XML Parser checks XML file is Well Formed and Verified or not.
XML parser parses XML documents and sends data to display in a
browser.
The job of parser is to make sure that document meets the defined
structures, validation and constraints.
XML Rules
Every XML document can have only one root
element.
Every start tag must have end tag.
WSDL describes
Client ‘s application Web Service
1 Locates (Searches)
3
Web Service in UDDI
4
Client
Application Web Service
Communication b/w
Client & web services
Through SOAP
First of all client application searches for the web application.
we have already discussed that after creating services, they
are registered under UDDI.
So when any client’s application wants to access any web
service, it searches for web service under UDDI.
If Web Service is registered , UDDI gives its location in a
format of WSDL document.
We have already discussed that WSDL is XML based
descriptor which describes web application.
Location of WSDL is given by UDDI.
CREATING A WEB SERVICE
Step (1) : Select File -> New -> Web Site in Visual
Studio, and then select ASP.NET Web Service.
Step (2) : A web service file called Service.asmx
and its code behind file, Service.cs is created in the
App_Code directory of the project.
Step (3) : Change the names of the files to
StockService.asmx and StockService.cs.
Step (4) : The .asmx file has simply a WebService
directive on it:
<%@ WebService Language="C#" CodeBehind="~/App_Code/StockService.cs"
Class="StockService" %>
Step (5) : Open the StockService.cs file, the code
generated in it is the basic Hello World service.
SAMPLE CODE OF A WEBSERVICE
CLASS
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
namespace StockService
{
// <summary>
// Summary description for Service1 // <summary> [WebService(Namespace = "http://tempuri.org/")]
//[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] // To allow this Web Service to be
called from script, // using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService]
[WebMethod]
}
}
WSDL describes Web Service and its embedded
Web Methods.
WSDL describes argument list(parameters) and
returns values of each web method within web
service. So that client can get the list of each of
web methods.
We discussed that UDDI gives location of web
service ad description in form of WSDL.
Now finally when client gets physical location of
WSDL, client can access Web Service via SOAP.
SOAP is communication protocol which allows you
to access web service and its Web Methods.
Step (6) : Change the code behind file to add the
two dimensional array of strings for stock symbol,
name and price and two web methods for getting
the stock information.
[WebMethod]
public double GetPrice(string symbol)
{
//it takes the symbol as parameter and returns price
for (int i = 0; i < stocks.GetLength(0); i++)
{
if (String.Compare(symbol, stocks[i, 0], true) == 0)
return Convert.ToDouble(stocks[i, 2]);
}
return 0;
}
[WebMethod]
public string GetName(string symbol)
{
{
<asp:Label ID="lblmessage"
runat="server"></asp:Label>
<br /> <br />
{
if (!IsPostBack)
{
}
}