WebService service Create, Invoke notes

Source: Internet
Author: User

Introduction 

Before using Windows Services, you learned and documented: the Creation, installation, debugging, and subsequent learning of Windows services. The need to use webservice today is confusing. After a few days of study, access to information, and finally roughly understand how to use, as to its fundamental principles, temporarily not fully understood, and later have the opportunity to study it in detail.

Defined: 

WebService is a platform-independent, low-coupling, self-contained, programmable programmable application that uses Open XML standards to describe, publish, discover, orchestrate, and configure these applications for the development of distributed, interoperable applications. (Baidu definition)

WEB Service technology enables different applications running on different machines to exchange data or integrate with each other without the use of additional, specialized third-party software or hardware. Applications that are implemented according to the Web Service specification can exchange data with each other, regardless of the language, platform, or internal protocol they are using. Web service is a self-describing, self-contained, available network module that can perform specific business functions. Web service is also easy to deploy because they are based on some common industry standards and some of the existing technologies, such as XML, HTTP. Web service reduces the cost of application interfaces. WEB Service provides a common mechanism for integration of business processes across the enterprise and even across multiple organizations.

Personal understanding: WebService is an independent platform, which is described by XML, which can help set up the data interaction mechanism of the system under different platform. For example, to create a webservice on a very large ASP. NET site, the system developed by other departments in the company needs to cite some data from the website, then create a webservice on the site, and other systems directly add the Web service to invoke a data or method on the site.

To create a simple webservice:

Tell me about the first small problem: I use visual studio2010, I can't find a Web service when I create a new project?

Directly select. net4.0, you can choose to create an ASP. NET empty template, and then add a new item to select a Web service template. This method is the simplest. Also: choose. net2.0,,3.0,3.5, you can choose the WebService template, then need. net4.0 new features, select the. net4.0 in the Project Properties window or the Build tab of the page window.

Create a new empty ASP. NET project, add the WebService page, write:

namespacefirstwebservice{/// <summary>    ///Summary description of WebService1/// </summary>[WebService (Namespace ="http://tempuri.org/")] [WebServiceBinding (ConformsTo=Wsiprofiles.basicprofile1_1)] [System.ComponentModel.ToolboxItem (false)]    //to allow the Web service to be called from the script using ASP. NET AJAX, uncomment the downstream. //[System.Web.Script.Services.ScriptService]     Public classWebService1:System.Web.Services.WebService {[WebMethod (Description="method of summation")]         Public DoubleAddition (DoubleIDoublej) {returni +J; } [WebMethod (Description="the method of finding the difference")]         Public DoubleSubtractDoubleIDoublej) {returnIJ; } [WebMethod (Description="the method of calculating the product")]         Public DoubleMultiplication (DoubleIDoublej) {returnIJ; } [WebMethod (Description="How to find a business")]         Public DoubleDivision (DoubleIDoublej) {if(J! =0)                returnIJ; Else                return 0; }       }}
View Code

At this point, a webservice is created that contains a subtraction of 4 methods.

ASP. NET Call WebService:

The following creates an ASP. Call WebService:

Start by referencing WebService and adding the service's website URL to the service reference.

Write the method of the call:

protected voidButton1_Click (Objectsender, EventArgs e) {            stringSelectflag =Selectoper.value; Servicereference1.webservice1soapclient Web=Newservicereference1.webservice1soapclient (); if(Selectflag.equals ("+") ) {Result.text= (Web.addition (Double. Parse (Num1.text),Double. Parse (Num2.text)).            ToString (); }            Else if(Selectflag.equals ("-") ) {Result.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 (); }            Else if(Selectflag.equals ("/") ) {Result.text= (Web.division (Double. Parse (Num1.text),Double. Parse (Num2.text)).            ToString (); }         }

WinForm Call WebService:

Since the above describes WebService when it is a boast platform, then create a WinForm system call WebService. Also add WebService first,

Private void button1_click (object  sender, EventArgs e)        {            new  Servicereference1.webservice1soapclient ();             this. Txt3. Text = (web.multiplication (double). Parse (thisdouble. Parse (this. Txt2. Text)). ToString ();        }

You can see that the WinForm call and the ASP. NET call are basically the same.

Summarize:

The basic understanding of WebService is briefly described above, then a fairly simple webservice is created, then an ASP. NET project is created and the WinForm system calls it, all of which basically completes the WebService's use of the process. You see more advanced webservice, or can be said to be more complex webservice bar, these are the simplest webservice based on the addition of some very complex business logic, cobwebs is still the basic WebService application.

WebService service Create, Invoke notes

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.