The previous article introduced some basic features of webservice and the structure of our example. This article will begin with the specific coding work.
This topic focuses on webservice. Therefore, our code here focuses on Webservice, while other projects, such as ServiceGatherSite and WebSiteA, will only be briefly introduced.
It is not difficult to develop a webservice in VS2003. First, create a webservice Project (file-> New-> Project-> C #-> Web service application)
After this project is created, we will see a file named Service1.asmx, which is the standard file of webservice. It also has the UI concept, but we generally do not pay attention to it. Therefore, we can view its cs code file. if you haven't done anything yet, you will see a commented-out helloworld WebMethod, remove the annotation, and run it to get the simplest webservice running instance. click "helloworld" to execute the method. obviously, this function only means to understand the web Service writing method at a macro level.
Next, we will introduce the webservice method in detail. in the code file, if we want this function to become an externally callable interface function after writing a function, we must add a line of code [WebMethod (Description = "function Description")] to the function. If your function does not have this Declaration, it cannot be referenced by users. for example:
[WebMethod (Description = "simplest method")]
Public string HelloWorld ()
{
Return "Hello World ";
}
This function is an externally callable interface function, which is equivalent to an API for users. if a user calls the HelloWorld () method after referencing this service, he will get the return value "HelloWorld.
We can see whether we have found that webservice is not so mysterious. It is just an interface. For us, the focus is on writing interface functions. below, I will provide the interface functions required for our example.