Web Service (0): Implementing two integer operations with Web service

Source: Internet
Author: User

Recently, Web service needs to be used in project development. I have made a small example of myself to deepen my understanding of Web service.

Concept: Web service is a kind of interface that is proposed to make the information between isolated sites communicate and share with each other. Web service uses uniform, open standards on the Internet, such as HTTP, XML, SOAP (Simple Object Access Protocol), WSDL, and so on, so Web service can be used in any environment that supports these standards (WINDOWS,LINUX). Note: The SOAP protocol, simple Object access Protocal, is an XML-based communication protocol for network information exchange in decentralized and distributed environments. Under this protocol, software components or applications can communicate through the standard HTTP protocol. It is designed to be simple and extensible, which facilitates interoperability between heterogeneous programs and platforms, so that existing applications can be accessed by a wide range of users.

This is the Web service server side MyWeb service.asmx file code:

1 usingSystem;2 usingSystem.Collections.Generic;3 usingsystem.web;4 usingSystem.Web.Services;5 6 /// <summary>7 ///Summary description of MyWebService8 /// </summary>9[WebService (Namespace ="http://tempuri.org/")]Ten[WebServiceBinding (ConformsTo =wsiprofiles.basicprofile1_1)] One  Public classMyWebService:System.Web.Services.WebService { A  -      PublicMyWebService () { -  the         //If you are using a design component, uncomment the following line -         //InitializeComponent (); -     } -[WebMethod (Description ="method of summation")] +      Public DoubleAddition (DoubleIDoublej) -     { +         returni +J; A     } at[WebMethod (Description ="the method of finding the difference")] -      Public DoubleSubtractDoubleIDoublej) -     { -         returnIJ; -     } -[WebMethod (Description ="the method of calculating the product")] in      Public DoubleMultiplication (DoubleIDoublej) -     { to         returnIJ; +     } -[WebMethod (Description ="How to find a business")] the      Public DoubleDivision (DoubleIDoublej) *     { $         if(J! =0) Panax Notoginseng         {  -             returnIJ; the         }  +         Else A         { the             return 0; +         } -     } $}

This is the client foreground index.aspx file code:

1<%@ Page language="C #"autoeventwireup="true"codefile="Index.aspx.cs"inherits="Index"%>2 3<! DOCTYPE html>4 5"http://www.w3.org/1999/xhtml">6"Server">7<title></title>89<body>Ten<form id="Form1"runat="Server"> One<div> A<asp:textbox id="Num1"runat="Server"></asp:TextBox> -<SelectId="Selectoper"runat="Server"> -<option>+</option> the<option>-</option> -<option>*</option> -<option>/</option> -</Select> +<asp:textbox id="Num2"runat="Server"></asp:TextBox> -<asp:button id="Button1"runat="Server"text="="onclick="Button1_Click"/> +<asp:textbox id="Result"runat="Server"></asp:TextBox> A</div> at</form> -</body> -

This is the client Index.aspx.cs file code:

1 usingSystem;2 usingSystem.Collections.Generic;3 usingsystem.web;4 usingSystem.Web.UI;5 usingSystem.Web.UI.WebControls;6 7  Public Partial classIndex:System.Web.UI.Page8 {9     protected voidPage_Load (Objectsender, EventArgs e)Ten     { One  A     } -     protected voidButton1_Click (Objectsender, EventArgs e) -     { the         stringSelectflag =Selectoper.value; -Mywebservice.mywebservice Web =NewMywebservice.mywebservice (); -         if(Selectflag.equals ("+")) -         { +Result.text= (Web.addition (Double. Parse (Num1.text),Double. Parse (Num2.text)). ToString (); -         } +         Else if(Selectflag.equals ("-")) A         { atResult.text = (Web.subtract (Double. Parse (Num1.text),Double. Parse (Num2.text)). ToString (); -         } -         Else if(Selectflag.equals ("*")) -         { -Result.text = (Web.multiplication (Double. Parse (Num1.text),Double. Parse (Num2.text)). ToString (); -         } in         Else if(Selectflag.equals ("/")) -         { toResult.text = (Web.division (Double. Parse (Num1.text),Double. Parse (Num2.text)). ToString (); +         } -     } the}

In this way, an ASP. NET Web site access is implemented with two integer operations using a Web service service.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.