Webservice Service creation, call notes, webservice notes

Source: Internet
Author: User

Webservice Service creation, call notes, webservice notes

Introduction 

In the past, I used windows Services, so I learned and recorded the whole process of creating, installing, and debugging windows Services and subsequent learning. Webservice is now needed, which is confusing. After several days of study and materials reading, I finally figured out how to use it. As for its fundamental principles, I cannot fully understand it yet. I will have the opportunity to study it in detail later.

 

Definition: 

Webservice is a platform-independent, low-coupling, self-contained, programmable-based application, you can use open xml standards to describe, publish, discover, coordinate, and configure these applications for Distributed interoperability applications. (Defined by Baidu)

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

Personal Understanding: webservice is an independent platform that is described in xml. It can help systems on different platforms establish data interaction mechanisms. For example, if you create a webservice on a very large asp.net website and the system developed by other departments in the company needs to reference some website data, create a webservice on the website, other systems can directly add web services to call a data or method on the website.

 

Create a simple webservice:

I encountered the first small problem: I used visual studio2010. Why can't I find the web service when I create a project?

Select. net4.0 directly. You can create an empty asp.net template and add a new project to select a web Service template. This method is the simplest. Also: select. for net2.0, 3.0, 3.5, you can select the webservice template. for new features of net4.0, select in the Project Properties window or in the Build tab of the page window. net4.0.

Create an empty asp.net project, add the webservice page, and write:

Namespace FirstWebservice {// <summary> // summary of WebService1 /// </summary> [WebService (Namespace = "http://tempuri.org/")] [WebServiceBinding (ConformsTo = WsiProfiles. basicProfile1_1)] [System. componentModel. toolboxItem (false)] // to allow ASP. net ajax calls this Web service from the script. Please cancel the comments to the downstream. // [System. web. script. services. scriptService] public class WebService1: System. web. services. webService {[WebMethod (Description = "summation method")] public double addition (double I, double j) {return I + j ;} [WebMethod (Description = "")] public double subtract (double I, double j) {return I-j ;} [WebMethod (Description = "Product Method")] public double multiplication (double I, double j) {return I * j ;} [WebMethod (Description = "method of quotient")] public double division (double I, double j) {if (j! = 0) return I/j; else return 0 ;}}}View Code

Now a webservice is created, which contains four methods: addition, subtraction, multiplication, division, and so on.

 

Asp.net calls webservice:

Create an asp.net project to call webservice:

First, reference webservice and add the website URL of the Service to the service reference.

Compile the call method:

protected void Button1_Click(object sender, EventArgs e)        {            string selectFlag = selectOper.Value;            ServiceReference1.WebService1SoapClient web = new ServiceReference1.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 calls webservice:

Since we mentioned webservice as a platform, we have created a winform system to call webservice. Add webservice first,

private void button1_Click(object sender, EventArgs e)        {            ServiceReference1.WebService1SoapClient web = new ServiceReference1.WebService1SoapClient();            this.txt3.Text = (web.multiplication(double.Parse(this.txt1.Text), double.Parse(this.txt2.Text))).ToString();        }

We can see that the winform call and asp.net call are basically the same.

 

Summary:

The preceding section briefly describes the basic knowledge of webservice, creates a relatively simple webservice, and then creates an asp.net project and a winform system to call it, the use of webservice is basically complete. We usually see more advanced WebServices, or more complex WebServices. These are complex business logic added on the basis of the simplest webservice, it is also a basic webservice application.

 

 

 

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.