How to create and publish an. asmx Web Service

Source: Internet
Author: User
Tags log4net

Create and publish a Web Service
A DataSet object can be returned in a Web service method

Web services can be said to be the foundation of next-generation Web applications, regardless of whether the client is a Windows application, an ASP. NET Web Form program, or even a client in another language, can communicate with the same WEB service, its platform and language independence gives it a broad 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. First create a new Web service project in VS2005.

Open file, new, Web site, and in the dialog box, select ASP. VS2005 automatically generates a Service.cs file with 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 are using a design component, uncomment the following line
  10. //initializecomponent ();
  11. }
  12. [WebMethod]
  13. public String HelloWorld () {
  14. return "Hello World";
  15. }
  16. }


You can modify your own namespace here, add your own method, but this article just to illustrate how to create and publish, so do not make any changes to Service.cs. It may be necessary to add DLLs to the project, such as Log4net.dll, in addition to being declared in the code: using Log4net; There is also the right-add reference-add the DLL on the project. It will eventually be added to the Bin folder of the project's root directory.

2. Build a Web site

Very simple, "build", "Build Web Site" or direct SHIFT+F6

3. Publishing a website

is also simple, "build", "publishing Site", here will pop up a dialog box, nothing to modify, note the published directory. For example, C: \ My document \visual Studio 2005\projects\website1\precompiledweb\website1, we need the files in the directory.

4. Configure IIS

In Windows Server 2003, for example, if IIS is not installed on the server, you must first install:

Control Panel Add Remove, Add/Remove components, application Server, Internet Information Services

If the installation process requires 2003 of the data on the installation CD, specifically, such as the CD-ROM ISO file after decompression:

Cn_win_srv_2003_r2_enterprise_with_sp2_vl_cd1\i386

Then choose what is prompted on the dialog box, such as Iisback.vb_

Enter IIS:

Internet Information Services Manager, Administrative Tools

Create a new virtual directory under the IIS Manager-Web site-Default Web site (or create a new one yourself), such as WebService, and copy all the files and directories in the 3rd release directory to this directory, open IIS, locate your site, right-click on the WebService directory, Select Properties, in the "Virtual directory" tab of the Pop-up dialog box, after the application name, click the "Create" button, then OK.

By this time, it should have been completed, you can verify by accessing http://Domain/webservice/service.asmx.

At this point, it is still possible to have a bad access and, if there is no ASP. NET tab in the WebService virtual directory created above, it is likely that the problem is as follows.

Attention:

When the program may need to run on the Framework2.0 framework, the default. NET environment in IIS is 1.1. An unrecognized node problem occurs.

Workaround:

Upgrade. NET environment to 2.0, start-to-run, cmd-

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe-i

Sometimes you will still be prompted to install the. NET Framework 3.5 or later

After the installation is complete, there may be some minor problems, such as no permissions to execute the script ah, then in the virtual directory-Execute permissions to select the pure script

If there are 404, then:

JS Code
  1. IIS access aspx file display 404 can't find the file?
  2. Workaround:
  3. Microsoft Windows [version 5.2.3790]
  4. (C) Copyright 1985-2003 Microsoft Corp.
  5. C:\Documents 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 installation of ASP. NET (2.0.50727).
  10. .........................................................
  11. ASP. NET (2.0.50727) installation is complete.
  12. C:\windows\microsoft.net\framework\v2.0.50727>

Referenced from: http://www.cnblogs.com/mrray/archive/2010/11/24/1886300.html

See the Run Web page right-click on the asmx file to browse directly.

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.