Sameer Gaikwad Web Service meameergaikwad

introduction 

This composition describes how to produce a web service inASP.NET and use it in a customer operation.  



What are Web Services? 

     There's further than one way to answer, “ What's a web service?” But, basically, web services take in any software, operation, or pall technology that provides standardized web protocols (HTTP or HTTPS) to interoperate, communicate, and exchange data messaging – generally XML [Extensible-Markup-Languages] --– throughout the internet. 

     In different expressions, web services are XML- centered data exchange networks that apply the internet for A2A (operation-to-operation) communication and interfacing. These operations involve schedules, dispatches, documents, and/ or things. 

     A crucial point of web services is that operations can be written in colorful languages and are still suitable to communicate by swapping data with one another via a web service between guests and waiters. A customer process a web service by transferring a request via XML, and the service also responds with an XML response. Web services are also frequently associated with SOA ( Service- Acquainted Architecture). 

    To break up that down, a web service comprises these required functions. procurable over the internet or intranet networks 

     Formalized XML messaging network  Independent of an unattached operating complex or programming language Tone- describing via standard XML language Discoverable through a simple position system 
     A web service supports communication among multitudinous apps with HTML, XML, WSDL, Cleaner, and other open norms. XML markers the data, Cleaner transfers the communication, and WSDL describes the service’s availability. 
     Then’s a case of how it works A web service sits between two sets of java,. net, or PHP apps furnishing a way for these operations to communicate over a network. On one side, for illustration, a java app interacts with java,. net, and PHP apps on the nonidentical check by expressway of the web service communicating an independent language. 
     Web services give other advantages across custom charges. The technology helps IT pros and web engineers streamline connectivity by minimizing development time. And with this simplified structure, company directors begin to see advanced ROI ( return on investment). In a B2B operation where both parties understand how the process works, web services give effective technology distribution throughout an entire network. 



How to create a Web Service

 
Step 1
 
Go to Visual Studio also click on"New"->"Website"->"ASP.NET empty website template".



 
Also, give the website name (for illustration WebServiceSample).
 

 
 
Step 2 Add a Web Service File
 
Go to Solution Explorer, also elect the result also click on" Add-> Add new item".



 
Choose the Web Service template.
 
Enter the title (for sample Arithmetic.cs) also click on" Add".
 

 
 
This will make the following two lines
  1. Arithmetic.asmx( the service train)
  2. Arithmetic.cs (the law train for the service; it'll be in the"App_code" brochure)

 
 
Open the file Arithmetic.cs and write the following code
  1. using System;  
  2.  using System.Collections.Generic;  
  3.  using System.Linq;  
  4.  using System.Web;  
  5.  using System.Web.Services;  
  6.  /// <summary>  
  7.  /// used for Arithmetic calculation  
  8.  /// </summary>  
  9.  [WebService(Namespace = "http://tempuri.org/")]  
  10.  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]  
  11.  // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.  
  12.  // [System.Web.Script.Services.ScriptService]  
  13.  public class Arithmetic: System.Web.Services.WebService  
  14.  {  
  15.      public Arithmetic()   {  
  16.          //Uncomment the following line if using designed components  
  17.          //InitializeComponent();  
  18.      }  
  19.      [WebMethod]  
  20.      public int Add(int x, int y)  
  21.      {  
  22.          return x + y;  
  23.      }  
  24.      [WebMethod]  
  25.      public int Sub(int x, int y)  
  26.      {  
  27.          return x - y;  
  28.      }  
  29.      [WebMethod]  
  30.      public int Mul(int x, int y)  
  31.      {  
  32.          return x * y;  
  33.      }  
  34.      [WebMethod]  
  35.      public int Div(int x, int y)  
  36.      {  
  37.          return x / y;  
  38.      }  
  39.  }  




Attaching the WebMethod trait to a Public system indicates that you want the system exposed as part of the XML Web service. You can also use the parcels of this trait to further configure the geste of the XML Web service system. The WebMethod trait provides the following parcels
  • BufferResponse
  • CacheDuration
  • Description
  • EnableSession
  • MessageName
  • TransactionOption
For further details of the web, styles click then.
 
Step 3
 
To see whether the service is running rightly go to the Solution Explorer also open" Arithmetic.asmx" and run your operation.

 Now you'll find all the system names in the cybersurfer.

 

 
 
To experience the WSDL formation click on the service description link or add"? WSDL" to the URL.
 
Example
 
http://localhost:51595/Arithmetic.asmx?WSDL
 
It will show the WSDL.
 

 
 
To determine whether the functions are working, click on one of the functions (for sample" Add").
 

 

 

 
currently, you'll have two TextBoxes for answering. access the value for x and y and click on the" Invoke" button.




Now you'll have the development in an open standard form (XML).






 
Now your service is ready for use.
 
Step 4 Creating the client application

Go to Solution Explorer, also elect the result also click on" Add-> Add new item".




name the Web form.
 
Enter the name (for sample Default.aspx) also click on" Add".




 
currently result from a website and design your form as in the following big screen.


 

 
 
Or you can copy the following source code.
  1. <body>  
  2.      <form id="form1" runat="server">  
  3.      <div>  
  4.          <table border="2" cellpadding="2" cellspacing="2">  
  5.              <tr>  
  6.                  <td align="right">  
  7.                      <asp:Label ID="Label1" runat="server" Text="Enter 1st Number"></asp:Label>  
  8.                  </td>  
  9.                  <td align="left">  
  10.                      <asp:TextBox ID="txtFno" runat="server"></asp:TextBox>  
  11.                  </td>  
  12.              </tr>  
  13.              <tr>  
  14.                  <td align="right">  
  15.                      <asp:Label ID="Label2" runat="server" Text="Enter 2nd Number"></asp:Label>  
  16.                  </td>  
  17.                  <td align="left">  
  18.                      <asp:TextBox ID="txtSno" runat="server"></asp:TextBox>  
  19.                  </td>  
  20.              </tr>  
  21.              <tr>  
  22.                  <td align="right">  
  23.                      <asp:Label ID="Label3" runat="server" Text="Result"></asp:Label>  
  24.                  </td>  
  25.                  <td align="left">  
  26.                      <asp:Label ID="lblResult" runat="server"></asp:Label>  
  27.                  </td>  
  28.              </tr>  
  29.              <tr>  
  30.                  <td align="center">  
  31.                      <asp:Button ID="btnAdd" runat="server" Text="Add(+)" OnClick="btnAdd_Click" />  
  32.                  </td>  
  33.                  <td align="center">  
  34.                      <asp:Button ID="btnSub" runat="server" Text="Sub(-)" OnClick="btnSub_Click" />  
  35.                  </td>  
  36.              </tr>  
  37.              <tr>  
  38.                  <td align="center">  
  39.                      <asp:Button ID="BtnMul" runat="server" Text="Mul(*)" OnClick="BtnMul_Click" />  
  40.                  </td>  
  41.                  <td align="center">  
  42.                      <asp:Button ID="btnDiv" runat="server" Text="Div(/)" OnClick="btnDiv_Click" />  
  43.                  </td>  
  44.              </tr>  
  45.          </table>  
  46.      </div>  
  47.      </form>  
  48.  </body>  

copy the following source code Default.aspx Page




Step 5 Add a web reference to the Website
 
Go to Solution Explorer also elect the result also click on" Add Service Reference" also within the URL like the service reference path.


Add Service Reference also click on the"Advanced" button


 
Advanced also click on the" Add Web Reference" button



then click on the "ok"


(For example http://localhost:51595/Arithmetic.asmx) then click on the "Go" button.
 
currently, you'll have your service styles. Change the web reference name from"localhost" to any other title as you like (for sample Arithmetic).
 

Click on the" Add Web Reference" button. It'll generate a Proxy at the client side.


 
Add Web Reference then click on the "OK" button







 








 
Now go to the cs code and add a reference for the Service.
 
Example
 
using Arithmetic;
 
Write the following code.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using WebArithmetic;  
  8. public partial class _Default : System.Web.UI.Page  
  9. {  
  10.     Arithmetic obj = new Arithmetic();  
  11.     int a, b, c;  
  12.     protected void Page_Load(object sender, EventArgs e)  
  13.     {  
  14.     }  
  15.     protected void btnAdd_Click(object sender, EventArgs e)  
  16.     {  
  17.         a = Convert.ToInt32(txtFno.Text);  
  18.         b = Convert.ToInt32(txtSno.Text);  
  19.         c = obj.Add(a, b);  
  20.         lblResult.Text = c.ToString();  
  21.     }  
  22.     protected void btnSub_Click(object sender, EventArgs e)  
  23.     {  
  24.         a = Convert.ToInt32(txtFno.Text);  
  25.         b = Convert.ToInt32(txtSno.Text);  
  26.         c = obj.Sub(a, b);  
  27.         lblResult.Text = c.ToString();  
  28.     }  
  29.     protected void BtnMul_Click(object sender, EventArgs e)  
  30.     {  
  31.         a = Convert.ToInt32(txtFno.Text);  
  32.         b = Convert.ToInt32(txtSno.Text);  
  33.         c = obj.Mul(a, b);  
  34.         lblResult.Text = c.ToString();  
  35.     }  
  36.     protected void btnDiv_Click(object sender, EventArgs e)  
  37.     {  
  38.         a = Convert.ToInt32(txtFno.Text);  
  39.         b = Convert.ToInt32(txtSno.Text);  
  40.         c = obj.Div(a, b);  
  41.         lblResult.Text = c.ToString();  
  42.     }  
  43. }  





Now first run the Web service then the application.
 

 
 
right now you'll live suitable to communicate with the web service.



Web Services Summary 


 This tutorial has educated you on how to set up operations into network operations. 
 
 You have to learn how to use XML to shoot dispatches between operations. 

 You also learn how to export a function from the operation ( result from a web service). 

Post a Comment

0 Comments