How to create and publish a. asmx Web Service

Source: Internet
Author: User

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
  1. Using system;
  2. Using system. Web;
  3. Using system. Web. Services;
  4. Using system. Web. Services. Protocols;
  5. [WebService (namespace = "http://tempuri.org/")]
  6. [Webservicebinding (conformsto = wsiprofiles. basicprofile1_1)]
  7. Public class service: system. Web. Services. WebService {
  8. Public Service (){
  9. // If you use the designed component, uncomment the following line
  10. // Initializecomponent ();
  11. }
  12. [Webmethod]
  13. Public String helloworld (){
  14. Return "Hello World ";
  15. }
  16. }

 

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
  1. When IIS accesses the aspx file, 404 cannot find the file?
  2. Solution:
  3. Microsoft Windows [version 5.2.3790]
  4. (C) Copyright 1985-2003 Microsoft Corp.
  5. C: \ Documents ents and Settings \ Administrator> Cd C: \ WINDOWS \ microsoft.net
  6. C: \ windows \ Microsoft. NET> Cd FRA *
  7. C: \ windows \ Microsoft. NET \ framework> Cd V2 *
  8. C: \ windows \ microsoft. Net \ framework \ v2.0.50727> aspnet_regiis-I-enable
  9. Start installing ASP. NET (2.0.50727 ).
  10. ........................................ .................
  11. ASP. NET (2.0.50727) installation is complete.
  12. 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.

 

2010.09.02

After one release, we found that the remaining space on disk C on the server is zero, and the service is published on disk D. However, WebService is no longer accessible, and the service is unavailable, freeing up space and restarting.IIS Admin ServiceAfter the release, it is normal. After verification, after the release, the C disk is indeed 2 m smaller. It is estimated that the C disk space will be occupied after the release.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.