There are a lot of information about webservice on the internet, but most of them are not complete, and most of them are reproduced .... This tragedy, I have not tried to use on the irresponsible reprint.
So today on the new webservice, release, the use of the most comprehensive, meticulous exercise, if there is a question of the message, we discuss together.
First Build WebService
Tool: vs2013
1, we create a new Web project:
Choose an empty Web project just fine
Single Machine Determination
An empty Web project is established
2. Right-click the project name to add a Web service (asmx file)
Single-Machine add
So far we have built good one simplest webservice (webservice1.asmx)
3. We open the Webcervice1.asmx file:
We see the HelloWorld () method and our usual method above is just one more [WebMethod] logo, the meaning of this is to tell the environment I this method can be used as a Web service call.
4. Publish: Right-click on the project to publish:
Click Customize to enter any of the configuration names:
Publish method Select File system
Click Next, define the path of the publication yourself in the destination location, and then proceed to the next step, and finally publish.
We open our own defined release path to see:
There are 3 files in the path.
At this point our webservice is established and released.
Here's one place to note: If the version of. NET Framwor installed on your computer is inconsistent with the version you were building the project on, it will cause IIS to not be able to interpret your Web service. So to change the version of the. NET Framwork for the development environment before publishing:
Right-click the project name to select Properties:
The target framework chooses the appropriate version. I am here because I do not have the. NET Framwork 4.5 installed on my computer so the target frame I chose is version 4.0.
Two
The published Web servive must be published to the IIS server for external programs to access.
My Computer system is Win 7, you must install IIS.
Open Control Panel program and features, stand-alone "turn Windows features on or off"
Find [Internet Information Services]
Tick all the tree levels (because only IIS is installed completely for normal use, the best option when the IIS feature is not familiar with the full installation)
Wait a minute, wait until the installation is complete, but start the operating system, search for programs and files, type IIS, and locate IIS open.
Open your browser and type: http://localhost/iisstart.htm
Open as shown. To prove that the IIS installation was successful
2. Back to the open IIS interface, right-click on the website to create a new website
The website name is written casually, the application pool chooses. NET Framwork version and the version that you release is consistent (we release the version is 4.0, forget the child shoes can be turned over), IP type native IP, port number in order not to conflict we type 8012 (the default website is 80), Physical path Select the path where you publish the Web service.
After the new site is finished, switch IIS to the content view, right-webservice1.asmx the file, and browse to the browser.
Error, we see that the access failed due to insufficient permissions. (IIS edits the Web. config file, and if you do not have permissions, IIS cannot edit the file and the browse fails).
Solve the problem:
Locate the path where we published the Web Service project, add "security" to the right-click property of the folder, and type "everyone"
Single-Machine OK, the newly added user everyone selects Full control, all the way to determine.
Re-accessing Webservice1.asmx with IIS
Stand-alone HelloWorld return
<string xmlns= "http://tempuri.org/" >Hello World</string> ———————— prove my web Service has been published successfully with IIS, and other programs can invoke our web service across platforms.
Three
Application calls Web Service
We use VS to create a new Winfrom program, add a service reference in the new project name right-click "
Single-machine Add Web reference type the URL of the Webservice1.asmx file that we accessed with IIS above
To write the Web reference name arbitrarily (remember the name webreference), click Add Reference.
In our Winfrom program, enter the From1 constructor to write the following code:
Webreference.webservice1 w=new Webreference.webservice1 () '
String Str=w.helloworld ();
Break point, run to see what we define the str variable is helloword. This call succeeds.
. Net--webservice new, published, Used (most complete, simplest) "original"