Let us explore the creation of web services, and a client application that consumes the web service and finally we will talk about a transactional web service that seamlessly accesses a COM object to provide functionality to the consumers of the web services.

balecomputerSecurity

Nov 3, 2013 (4 years and 6 days ago)

109 views





Let us explore the creation of web services, and a client application
that consumes the web service and finally we will talk about a
transactional web service that seamlessly accesses a COM object to
provide functionality to the consumer
s of the web services.

We will create a simple Web Service to fetch “Movie Information”
over the Internet based on the parameters supplied by running a
query against the CDs table.

We will use SqlServer7.0 database having a CDs table that stores a list
of
the movies.

To create this Web service, we create a new Web service project and
add three methods. Call it
GetMoviesWebService
.


Then we will add the following methods to the web service.



CDByTitle

that provides list of CDs based on Title of the CD.



CD
ByArtist

that gives the list of CDs based on the Artist.



CDByCategory

that gives the list of CDs based on the Category.




<WebMethod()>
Public

Function

CDByTitle(
ByVal

strTitle
As

String
)
As

DataSet




Dim

oAdapter
As

OleDb.OleDbDataAdapter


Dim

oDS
As

DataSet


Dim

strSQL
As

String


Dim

strConn
As

String



strConn = "Provider=sqloledb;"


strConn &= "Data Source=(local);"


strConn &= "Initial Catalog=ITM;"


strConn &= "User ID=sa"



strSQ
L = "SELECT * FROM CDs "


strSQL &= "WHERE CDTitle LIKE '%" & strTitle & "%'"



oAdapter =
New

OleDb.OleDbDataAdapter(strSQL, strConn)


oDS =
New

DataSet()



oAdapter.Fill(oDS, "CDByTitle")



Return

oDS



End

Function


Complete the code for the rest of the functions and right click (asmx
file) in the project property window and “view in browser”, this is
required in order to test our web service, which shows as follows:






Build an Windows Application to consume our

newly developed web service


Open a new project and design your form to look as follows:




Private

Sub

Button1_Click(
ByVal

sender
As

System.Object,
ByVal

e
As

System.EventArgs)
Handles

Button1.Click


Dim

objTest
As

New

localhost.Service1()



txtReversed.Text = (objTest.ReverseName(txtName.Text))

End

Sub


Private

Sub

Button2_Click(
ByVal

sender
As

System.Object,
ByVal

e
As

System.EventArgs)
Handles

Button2.Click


Dim

ds
As

DataSet


Dim

WS
As

New

localhost1.Service1()


ds =

WS.CDByTitle(txtCDTitle.Text)


dgOrders.DataSource = ds.Tables("CDByTitle").DefaultView


End

Sub


Make sure you Add reference to the Web Service as shown




If everything goes right, you should be able to see the following data coming
from the
use of the web service.