1. Create WebService
Take VS2013 as an example, open the VS2013, select the new Project, "ASP. NET Web Application" under the Web classification, and note the top-of-the-box version, where we select 4.0 and then OK. Such as:
After you create a new project, add a new item--web service to the project, such as:
Double hit open this. asmx file, we can see the code corresponding to the. cs file, which has a default HelloWorld function, in which we manually add a sum Sum function, the final code is as follows:
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Services; namespace webservicetest{//<summary>///WebService1//</summary> [WebService (namespace = "http://tempuri.org/")] [webservicebinding (ConformsTo = wsiprofiles.basicprofile1_1)] [System.ComponentModel.Tool Boxitem (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 WebService1:System.Web.Services.WebService {[We Bmethod] public string HelloWorld () {return ' Hello world '; }///<summary>//To get the operand, a, and/or </summary>//<param name= "a" > Operand a< /param>//<param name= "B" > Operand b</param>//<returns></returns> [Webmetho D] public string Sum (int a, int b) {return string. Format ("{0}", a + B); } }}
At this point, a simple WebService program has been written to complete, generate code, run, will see the following results in the browser:
By clicking on the HelloWorld and SUM functions, you can debug the function function.
2. Publish the WebService
Right-click on the item, select Publish, and in the popup dialog box, do the following:
Write a profile name and click Next
Then click Next, and then click Publish.
After publishing is complete, you can see the corresponding file under the D:\WebSiteRoot\WebServiceTest path in the destination location.
And then configure IIS
Open IIS Manager, select Web site, right-click Add Web Site
Note: (1) The site name is filled out, application pool selection, select the program to run the required. Net framework version, be sure to select and new project is the same version
(2) Physical path, select the path of the program published above WebService (D:\WebSiteRoot\WebServiceTest)
(3) binding, IP address is not filled, or fill in the local IP address, modify the port, the port can not be used by other programs
As shown in the following:
After publishing is completed, Access is: Http://192.168.2.123:8666/Service.asmx or http://localhost:8008/Service.asmx If it appears, the publication is successful.
Sometimes you will encounter a lot of error, the following to organize these errors:
Error 1: Directory browsing problem:
This error can be ignored without modification, or can be modified according to the prompts in the webpage:
Workaround such as:
Error 2:
Error opening webservice1.asmx, "Parser error message: Failed to create type" Webservice1.service1 ".
WORKAROUND: First you must create a virtual directory in IIS (this is not much to say), if this time directly in the browser call WebService will be the above error. The reason is that you must create a separate application for the virtual directory created above, by right-clicking the virtual directory, clicking on "Add Application ...", the directory is identical to the physical path of the virtual directory, and the webservice can be used normally after the addition is complete!
Error 3:
HTTP Error 404.3-not Found
The page you requested could not be supplied due to an extended configuration issue. If the page is a script, add a handler. If you should download the file, add a MIME map.
The solution is as follows:
IIS7: Control Panel-turn on or turn off Windows features-Internet Information Services-Web services-application development features, tick ". NET extensibility" and "ASP.", and after saving, restart the IIS server.
IIS8: Control Panel-"Open or close Windows Features-" Internet Information Services-"Web services-" application development features, tick ". NET Extensibility3.5" and other options with. NET, after saving, restart the IIS server.
IIS does not check these options when it is installed by default.
Error 4: misconfiguration
Description: An error occurred while processing the configuration file required to service the request. Please check the specific error details below and modify the configuration file as appropriate.
Parser Error Message: Unrecognized property "TargetFramework". Note that property names are case-sensitive.
SOURCE Error:
Line 24: Set to True. Line:- Line: <compilation debug= "true" targetframework= "4.0"/> Line: <!-- |
Source file: E:\NET\CRM. Web\web.config Line : 26
Version info: Microsoft.NET Framework version: 2.0.50727.4961; ASP. NET version: 2.0.50727.4955
Workaround:
This error is caused by an inconsistency in the. NET Framework version and project that is selected in IIS, and modifies the version in IIS.
If you find that the application pool is selected without a corresponding framework version, select the new version in the application pool on the left.
Question 5:
HTTP error 500.21-internal Server error
Handler "webservicehandlerfactory-integrated" has an error module "Managedpipelinehandler" in its module list
Workaround:
This problem is caused by the fact that ASP. Net is not successfully registered with IIS, most likely by first installing the. Net Framework and then installing IIS
Access to cmd command prompt interface, execute command "C:\Windows\Microsoft.NET\Framework\v4.0.30319",
Run:
Aspnet_regiis.exe-i
Question 6:
Workaround:
There are many ways to solve this problem on the Internet, and I have no use trying it.
My solution is to refer to the release, re-create a new site in IIS, choose the appropriate path or something, just fine.
. NET WebService creation, publishing and FAQs