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 (); } }