WebService Introduction Demo

Source: Internet
Author: User

Before the most important thing to write a blog is not know what to write, now feel able to write something, is feeling the title of blog essay is very difficult to take, the recent work just used to webservice, just can write a blog. Last year when I used to work, just know to call some webservice in the method, think or write a blog, that is, as the saying goes, don't just walk down the head, but also pay attention to look up the sky. or write the text, and now every time you write a blog will be a little bit, do not take offense.

The basic concept of WebService

WebService the simple point of view of a name is a Web-based service that follows the HTTP protocol like a normal web program, receiving requests to respond to external programs and implementing remote calls. The data used by WebService is XML-formatted, so it is also called XML WebService. The current standard WebService uses the SOAP protocol in the data format (the SOAP protocol is actually a text protocol based on the XML Encoding specification), which is described using a WSDL file and registered with UDDI. (The specific concept can be Google's)

Creation of WebService

Web project Project New project, add a Web service

After adding the code as follows, are automatically generated (Hellworld seems to be the world will never be outdated)

<summary>    ///Myfirstwebservice Summary description///</summary> [WebService (Namespace = "/http// tempuri.org/")]    [webservicebinding (ConformsTo = wsiprofiles.basicprofile1_1)]    [ System.ComponentModel.ToolboxItem (false)]    //To allow the use of ASP. NET AJAX to invoke this Web service from a script, uncomment the following line.     //[System.Web.Script.Services.ScriptService] public    class Myfirstwebservice: System.Web.Services.WebService    {        [WebMethod] public        string HelloWorld ()        {            return ' Hello World ";        }    }

Publishing sites, new computers, installed VS2012, publishing projects and VS2010, publishing project projects, adding Web sites to local IIS, port setting is 7025.

Call of WebService

Create a new console program and add a service reference, such as:

Define the namespace yourself, and the next call is simple, and the code is as follows:

Class program    {        static void Main (string[] args)        {            SFM. Myfirstwebservicesoapclient Web = new SFM. Myfirstwebservicesoapclient ();            Console.WriteLine (web. HelloWorld ());            Console.readkey ();        }    }

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.