How to create and publish. asmx Web Service,. asmxservice
Create and publish a Web Service
A DataSet object can be returned in the Web service method.
WEB services are the foundation of the next generation of WEB applications, regardless of whether the client is a WINDOWS application, ASP. NET Web Form programs, and even clients in other languages, can communicate with the same WEB service. Their platform and language independence make it a vast space for development.
With VS2005 and IIS, we can easily publish a web service.
Environment: Windows Server 2003,. Net FrameWork 2.0, IIS6.0
Tool: VS2005
1. Create a new WEB Service Project in VS2005.
Open "file"-> "new"-> "website", and select "ASP. NET Web Service ", VS2005 will automatically generate a Service. the cs file contains the following code:
C # code
- Using System;
- Using System. Web;
- Using System. Web. Services;
- Using System. Web. Services. Protocols;
- [WebService (Namespace = "http://tempuri.org/")]
- [WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
- Public class Service: System. Web. Services. WebService {
- Public Service (){
- // If you use the designed component, uncomment the following line
- // InitializeComponent ();
- }
- [WebMethod]
- Public string HelloWorld (){
- Return "Hello World ";
- }
- }
You can modify your namespace and add your own methods here. However, this article only explains how to create and release your namespace, so you will not make any changes to Service. cs. You may need to add a dll in the project, for example, log4net. dll. In addition to declaring the use of using log4net in the code, you can also right-click the project, add reference, and add the dll. It will be added to the Bin folder in the root directory of the project.
2. Generate a website
Simple: "generate"-> "generate website" or directly Shift + F6
3. Publish a website
It is also simple. "generate"-> "Publish Website", a dialog box will pop up here, and there is no need to modify anything. Write down the published directory. For example, C: \ My document \ Visual Studio 2005 \ Projects \ WebSite1 \ PrecompiledWeb \ WebSite1, we need files in the directory.
4. Configure IIS
Take windows server 2003 as an example. If iis is not installed on the server, you must first install:
Control Panel add Delete> Add/delete Components> Application Server> Internet Information Service
For example, if 2003 of the data on the CD is required during the installation process, the corresponding information is as follows:
Cn_win_srv_2003_r2_enterprise_with_sp2_vl_cd1 \ I386
Then select what is prompted on the dialog box, such as IISBACK. VB _.
Enter IIS:
Management tools> Internet Information Service Manager
Create a virtual directory, such as webservice, under IIS Manager-website-default website (or create another website by yourself, copy all the files and directories in the release directory in step 1 to this directory, open IIS, find your site, right-click the webservice directory, and select Properties, in the displayed dialog box, click "virtual directory", select the project name, click "CREATE", and click "OK.
At this time, it should have been completed. You can access http: // domain name/webservice/Service. asmx for verification.
At this point, it may still be difficult to access and if there is no asp.net tab in the webservice virtual directory created above, it is likely to be the following problem.
Note:
When the program may need to run on the framework of Framework2.0, the default. net environment in iis is 1.1. In this case, an unrecognized node will occur.
Solution:
Upgrade the. net environment to 2.0, start-> Run-> cmd->
C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_regiis.exe-I
Sometimes you will still be prompted to install. net framework 3.5 or later.
After the above installation is complete, there may still be some minor problems. For example, if you do not have the permission to execute the script, select the pure script in the virtual directory-execution permission.
If there is another 404, then:
Js Code
- When iis accesses the aspx file, 404 cannot find the file?
- Solution:
- Microsoft Windows [version 5.2.3790]
- (C) Copyright 1985-2003 Microsoft Corp.
- C: \ Documents ents and Settings \ Administrator> cd c: \ windows \ microsoft.net
- C: \ WINDOWS \ Microsoft. NET> cd fra *
- C: \ WINDOWS \ Microsoft. NET \ Framework> cd v2 *
- C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727> aspnet_regiis-I-enable
- Start installing ASP. NET (2.0.50727 ).
- ........................................ .................
- ASP. NET (2.0.50727) installation is complete.
- C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727>
Reference from: http://www.cnblogs.com/mrray/archive/2010/11/24/1886300.html
View the running webpage and right-click the asmx file to view it.
C # How to publish a webservice? The more detailed the better.
In fact, it is very simple. First, make sure that the asmx method written in the website project has passed the debugging without any problems and the [WebMethod] is added before the method. right-click Project name-release in solution manager. After the release is successful, choose my computer> Manage> Internet Information Service> website> default website, right-click the default website, and choose create virtual directory, put the website you just published in IIS and set it for use. Test: Click the new virtual directory in IIS and find your published WEB service file, such as webservice1.asmx. Right-click and choose browse. If the file shows that the method you wrote is successful.
For WebService
VS has done this for you. You can create an asmx file and write WebMethod to publish the file. If you need to reference the file, press the asmx url and click OK.
You can right-click the project to add-> NewItem-> Web Service, that is, the. asmx file. By default, there is a WebMethod that is HelloWorld, and the string type returns the value.
I set it to port 80 on IIS, which is the default website port.
Localhost/TestWebService. asmx
Right-click the url you want to reference, add WebReference, add the url above to the url, and click the GO button.
After adding a reference, you will see three more files in the project, one is. discomap, the other is. disco, and the other is. wsdl.
(Not necessarily three. If your WebService uses other references, it will also be downloaded)
Wsdl is the abbreviation of Web Services Description Language. The Web Service Description Language is essentially an xml. It seems that the Web Service published in java provides a wsdl, after you get the wsdl, use the VS command line to compile and use it again. net.
---------------------------------------------
Here are the specific operation steps.
Book.77169.org/..7.html