0% found this document useful (0 votes)
3 views

aspnet7

The document provides an overview of XML and its usage in ASP.NET, including how to read and write datasets using XML methods such as WriteXml() and ReadXml(). It also explains the concept of Web Services, their integration with ASP.NET, and the standards/protocols involved, including XML, SOAP, WSDL, and UDDI. Additionally, it outlines the steps to create a simple Web Service in Visual Studio with example code for basic arithmetic operations.

Uploaded by

ritenpanchasara
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

aspnet7

The document provides an overview of XML and its usage in ASP.NET, including how to read and write datasets using XML methods such as WriteXml() and ReadXml(). It also explains the concept of Web Services, their integration with ASP.NET, and the standards/protocols involved, including XML, SOAP, WSDL, and UDDI. Additionally, it outlines the steps to create a simple Web Service in Visual Studio with example code for basic arithmetic operations.

Uploaded by

ritenpanchasara
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

SHREE SWAMI VIVEKANAND COLLEGE

SURENDRANAGAR
CLASS:- BCA/BSCIT SEMESTER -5
SUBJECT:- Asp.net
Prepared By:- Bhartiba parmar
Chapter-4
Using Xml
• Contents
What is xml?
Reading datasets from xml
Writing dataset with xml
What is webservice?
Creating a webservice.
 What is xml
• Xml (eXtensible Markup Language) is a mark up language.
• XML is designed to store and transport data.
• Xml was released in late 90’s. it was created to provide an easy to use and store
self describing data.
• XML became a W3C Recommendation on February 10, 1998.
• XML is not a replacement for HTML.
• XML is designed to be self-descriptive.
• XML is designed to carry data, not to display data.
• XML tags are not predefined. You must define your own tags.
• XML is platform independent and language independent.
There are basic rules for building XML:
All XML must have a root element.
All tags must be closed.
All tags must be properly nested.
Tag names have strict limits.
Tag names are case sensitive.
Tag names cannot contain spaces.
Attribute values must appear within quotes ("").
White space is preserved.
HTML tags should be avoided (optional).
Write XML Data
Writing Dataset or DataTable as XML is done by using two methods.
1)WriteXml() Method
2)WriteXmlSchema() Method

1)WriteXml() method

• This method is used to read data from Dataset and write data as XML data.
• While writing dataset you should consider following things.
• All tables of datasets are treated as Main Elements.
• All rows of tables are treated as sub elements.
• All columns of tables are treated as data elements which has actual data of table.
• There is only one Root Element in xml file.

2)WriteXmlSchema() Method

• XmlSchema is a file which contains rules for Xml Element and their data.If you use only WriteXml()
method,only data is written as Xml.But if you want to write schema information,you can use
WriteXmlSchema() method.
Examle

protected void btn_WriteDataSet_Click(object sender, EventArgs e)


{
SqlConnection connection = new SqlConnection(conectionstring);
SqlDataAdapter da = new SqlDataAdapter("select * from student", con);
DataSet ds = new DataSet();
da.Fill(ds);
ds.WriteXml(MapPath(“studXml.xml"));
GridView1.DataSource = ds;
GridView1.DataBind();

}
Read Xml Data
• There are two methods for reading datasets with XML.

1)ReadXml() Method
2)ReadXmlSchema() method

1)ReadXml() Method

• This method is used to read Xml data from any Xml file to dataset or datatable.
• While reading dataset or datatable it does as follows
• It treats all main elements under root element as different tables,if you are using DataSet to read
the data.
• It automatically stores data in xml way,because you are already reading a file which is in xml
format.

2) ReadXmlSchema() method

• If you use only ReadXml() method.It just reads entire data from Xml and stores it into DataSet or
DataTable.But before reading Xml data into DataSet,if you want to specify some schema
rules(data rules) before writing xml data to DataSet/DataTable,you can use ReadXmlSchema()
which allows you to specify XSD file and it restrics the data being copied into DataSet/DataTable.
Example
protected void btn_ReadXml_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(MapPath("StudXml.xml"));
GridView1.DataSource = ds;
GridView1.DataBind();
}
What is WebService?

• Web Services is an Internet-based integration methodology that enables


applications, independent of any platform or language, to connect and
exchange information.
• Web Services is tightly integrated with the ASP.NET model used for the
.NET Framework. Unlike traditional native Windows applications, ASP.NET
Web Services applications contain objects and methods that are exposed
over the Web using simple messaging protocol stacks.
• Any client can invoke a Web Services application over HTTP using a
WebMethod. Like any method that can be accessed by way of a simple
Windows Form application, a WebMethod provides some defined
functionality. Unlike other types of methods, however, the WebMethod is
accessed by way of a web browser.
• There are various standards/protocols that works behind web service.

1) XML(eXtensible Markup Language)


2) SOAP(Simple Object Access Protocol)
3) WSDL(Web Services Description Language)
4) UDDI(Universal Description Discovery and Integration)
• XML (Extensible Markup Language). XML is a user-defined, human-readable
structural description of data. Any data, dataset, or document that you intend to
send to, or receive from, a web service is formatted in XML.
• SOAP (Simple Object Access Protocol). SOAP is the standard messaging protocol
that is used for communication between web services and their clients. SOAP
uses XML to format its messages, and contains the parameters or return values
needed by servers and clients.
• WSDL (Web Services Description Language). WSDL is the language that describes
a web service. A web service can be defined in any number of implementation
languages. As a single-purpose utility, each web service must publish a
description of its interface, which allows clients to interact with it. The WSDL
document, at a minimum, describes the required parameters a client must
provide and the result a client can expect to receive. The result description
typically consists of the return data type.
• UDDI (Universal Description, Discovery, and Integration). UDDI is an industry
initiative that provides a standard repository where businesses can publish web
services for use by other companies. The UDDI repository contains links to, and
descriptions of, a variety of web services. You can use the UDDI browser in the
IDE to locate web services, download WSDL documents, and access additional
information about web services and the companies that provide them.
How to create a Web Service

Go to Visual Studio then click on "File" -> "Website" -> "ASP.NET empty website template".

Then provide the website name (for example: WebServiceSample).


Add a Web Service File
Go to Solution Explorer, then select the solution then click on "Add new item".
Choose the Web Service template.
Enter the name (for example: Airthmatic.cs) then click on "Add".
This will create the following two files:
Airthmatic.asmx (the service file)
Airthmatic.cs (the code file for the service; it will be in the "App_code" folder)
Open the file Airthmatic.cs and write the following code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Airthmatic : System.Web.Services.WebService
{
public Airthmatic() {
}
[WebMethod]
public int Add(int x, int y)
{
return x + y;
}
[WebMethod]
public int Sub(int x, int y)
{
return x - y;
}
[WebMethod]
public int Mul(int x, int y)
{
return x * y;
}
[WebMethod]
public int Div(int x, int y)
{
return x / y;
}
}

You might also like