Categories:
.NET (961)
C (387)
C++ (185)
CSS (84)
DBA (8)
General (31)
HTML (48)
Java (641)
JavaScript (220)
JSP (109)
JUnit (31)
MySQL (297)
Networking (10)
Oracle (562)
Perl (48)
Perl (9)
PHP (259)
PL/SQL (140)
RSS (51)
Software QA (28)
SQL Server (5)
Struts (20)
Unix (2)
Windows (3)
XHTML (199)
XML (59)
Other Resources:
What are the steps to create a webservice and consume it
What are the steps to create a webservice and consume it ?
✍: Guest
Note :- For this question this book will make a attempt by creating a simple webservice and
explaining steps to acheive it. A simple webservice will be created which takes two number
and gives addition result of the two number. In CD sample webservice project with folder
name MathsWebService is provided and same will be explained below. Definitely the
interviewer will not expect such a detail answer but this book will explain you in detail so
that you are on right track during interview.
This webservice will add two numbers and give to the calling client.All the below steps
are according to VS2005 beta editor :-
ã First create a website by clicking on File -- New WebSite.
ã From gVisual Studio Installed Templatesh click on gAsp.NET Web Serviceh.
See figure below. Name the figure as gMaths Web Serviceh.
By default the .NET editor has made a default webservice method called as
"HelloWord" which returns a string datatype. Let's rename "Service.vb" to
"Maths.vb" and "Service.asmx" to "Maths.asmx". Lets replace the
HelloWorld with following code below :-
<WebMethod()> _
Public Function AddTwoNumbers(ByVal Number1 As Integer, ByVal
Number2 As Integer) As Integer
Return Number1 + Number2
End Function
After the webservice is done click on add Webreference. Normally for
components we do a Add Reference and for Webservices we do Add Web
Reference.
You will be shown with a list of webservices which are known to the
solutions. As we are looking for our Maths webservice which exist in the
same solution, we click Webservices in this solution.
ã Your editor has located the gMathsh webservice.Select the webservice.
After you have clicked on Maths webservice you will see a search progress
bar as shown in figure below. This process will start the webservice, reference it
and create a proxy for the client, so that using it client can absorb the
webservice.
Finally you are able to see your webservice which is ready for use. Click on
Add Reference and you will see a Localhost reference in your .NET solution.
We need to make a client who will absorb this Maths Webservice. Add
WebserviceClient.aspx and create a UI as shown below. In the button click
put in the following code. LocalHost.ClsMaths is the proxy object by which
you can make calls to the webservice.
Sub cmdCalculate_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim pobjMaths As New localhost.ClsMaths
lblResultDisplay.Text =
Convert.ToString(pobjMaths.AddTwoNumbers(Convert.ToInt16(txtNumber1.Text),
Convert.ToInt16(txtNumber2.Text)))
End Sub
2007-10-23, 4708👍, 0💬
Popular Posts:
Why is there extra white space before or after tables? This is often caused by invalid HTML syntax. ...
How do we get the current culture of the environment in windows and ASP.NET?
How can you write a loop indefinitely? Two examples are listed in the following code: for(;;) { ... ...
How can you raise custom errors from stored procedure ? The RAISERROR statement is used to produce a...
How To Wirte a Simple JUnit Test Class? This is a common test in a job interview. You should be able...