How To List Two Services On Website
Introduction
This article describes how to create a spider web service in ASP.NET and apply it in a client application.
What is Web Service?
A Web Service is a reusable piece of code used to communicate among Heterogeneous Applications.
Once a web service is created and hosted on the server in the net it can be consumed past any kind of awarding developed in whatsoever engineering science.
How to create a Web Service
Step 1
Become to Visual Studio then click on "File" -> "Website" -> "ASP.NET empty website template".
And so provide the website name (for example: WebServiceSample).
Step two Add a Web Service File
Get to Solution Explorer, and then select the solution so click on "Add new item".
Choose the Web Service template.
Enter the name (for example: Airthmatic.cs) then click on "Add".
This volition create the post-obit 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 post-obit code
- using Organisation;
- using Arrangement.Collections.Generic;
- using Organisation.Linq;
- using System.Web;
- using Organisation.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)
- {
- render x + y;
- }
- [WebMethod]
- public int Sub( int x, int y)
- {
- return x - y;
- }
- [WebMethod]
- public int Mul( int ten, int y)
- {
- return ten * y;
- }
- [WebMethod]
- public int Div( int x, int y)
- {
- return ten / y;
- }
- }
Attaching the WebMethod attribute to a Public method indicates that you lot want the method exposed every bit part of the XML Spider web service. You lot tin also utilise the properties of this attribute to farther configure the behavior of the XML Spider web service method. The WebMethod aspect provides the following properties
- BufferResponse
- CacheDuration
- Description
- EnableSession
- MessageName
- TransactionOption
For more details of web methods click here.
Step three
To encounter whether the service is running correctly go to the Solution Explorer then open "Airthmatic.asmx" and run your application.
Now you volition find all the method names in the browser.
To see the WSDL format click on the service clarification link or add "?WSDL" to the URL.
Example
http://localhost:65312/WebServiceSample/Airthmatic.asmx?WSDL
Information technology will show the WSDL.
To make up one's mind whether the functions are working, click on one of the functions (for example: "Add").
Now yous will see ii TextBoxes for checking. Enter the value for 10 and y and click on the "Invoke" button.
Now you volition see the effect in an open standard form (XML).
Now your service is gear up for utilise.
Step 4 Creating the client application
At present create a website and design your form every bit in the post-obit screen.
Or you can copy the following source code.
- <body>
- <form id="form1" runat= "server" >
- <div>
- <tabular array border="2" cellpadding= "two" cellspacing= "two" >
- <tr>
- <td align="right" >
- <asp:Label ID="Label1" runat= "server" Text= "Enter 1st Number" ></asp:Label>
- </td>
- <td marshal="left" >
- <asp:TextBox ID="txtFno" runat= "server" ></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td align="correct" >
- <asp:Characterization ID="Label2" runat= "server" Text= "Enter 2nd Number" ></asp:Label>
- </td>
- <td marshal="left" >
- <asp:TextBox ID="txtSno" runat= "server" ></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td align="right" >
- <asp:Label ID="Label3" runat= "server" Text= "Consequence" ></asp:Characterization>
- </td>
- <td marshal="left" >
- <asp:Characterization ID="lblResult" runat= "server" ></asp:Label>
- </td>
- </tr>
- <tr>
- <td align="center" >
- <asp:Button ID="btnAdd" runat= "server" Text= "Add(+)" OnClick= "btnAdd_Click" />
- </td>
- <td align="center" >
- <asp:Button ID="btnSub" runat= "server" Text= "Sub(-)" OnClick= "btnSub_Click" />
- </td>
- </tr>
- <tr>
- <td align="eye" >
- <asp:Push ID="BtnMul" runat= "server" Text= "Mul(*)" OnClick= "BtnMul_Click" />
- </td>
- <td align="center" >
- <asp:Button ID="btnDiv" runat= "server" Text= "Div(/)" OnClick= "btnDiv_Click" />
- </td>
- </tr>
- </table>
- </div>
- </form>
- </body>
Step 5 Add a web reference to the Website
Become to Solution Explorer so select the solution and then click on "AddWeb Reference" then inside the URL type the service reference path.
(For example: http://localhost:65312/WebServiceSample/Airthmatic.asmx) then click on the "Become" button.
Now you volition see your service methods. Alter the web reference name from "localhost" to any other name as you similar (for example: WebAirthmatic).
Click on the "Add Reference" button. It will create a Proxy at the customer side.
Now go to the cs code and add a reference for the Service.
Instance
using WebAirthmatic;
Write the following code.
- using System;
- using System.Collections.Generic;
- using Organisation.Linq;
- using System.Web;
- using Organisation.Web.UI;
- using System.Web.UI.WebControls;
- using WebAirthmatic;
- public partial class _Default : System.Web.UI.Page
- {
- Airthmatic obj =new Airthmatic();
- int a, b, c;
- protected void Page_Load(object sender, EventArgs due east)
- {
- }
- protected void btnAdd_Click(object sender, EventArgs e)
- {
- a = Convert.ToInt32(txtFno.Text);
- b = Convert.ToInt32(txtSno.Text);
- c = obj.Add(a, b);
- lblResult.Text = c.ToString();
- }
- protected void btnSub_Click(object sender, EventArgs e)
- {
- a = Catechumen.ToInt32(txtFno.Text);
- b = Catechumen.ToInt32(txtSno.Text);
- c = obj.Sub(a, b);
- lblResult.Text = c.ToString();
- }
- protected void BtnMul_Click(object sender, EventArgs east)
- {
- a = Convert.ToInt32(txtFno.Text);
- b = Catechumen.ToInt32(txtSno.Text);
- c = obj.Mul(a, b);
- lblResult.Text = c.ToString();
- }
- protected void btnDiv_Click(object sender, EventArgs e)
- {
- a = Convert.ToInt32(txtFno.Text);
- b = Catechumen.ToInt32(txtSno.Text);
- c = obj.Div(a, b);
- lblResult.Text = c.ToString();
- }
- }
Now first run the Web service then the application.
Now you volition be able to communicate with the web service.
How To List Two Services On Website,
Source: https://www.c-sharpcorner.com/UploadFile/29d7e0/steps-to-create-a-simple-web-service-and-use-it-in-Asp-Net/
Posted by: loofas1938.blogspot.com
0 Response to "How To List Two Services On Website"
Post a Comment