ASP.NET Web服务和IIS的初学者问题

时间:2011-05-31 17:56:29

标签: c# asp.net xml web-services iis

我是.NET的新手。现在我正在尝试制作我的第一个ASP.NET Web服务。

我创建ASP.NET Web服务项目并使用Visual Studio 2010生成的默认Web方法。

我在Visual Studio中测试了这项服务,效果很好。

然后我在IIS上添加了虚拟目录,目录名是test。我使用的是Windows Server 2003 Standard。

尝试通过localhost访问Web服务。

http://localhost/test/Service1.asmx

我收到此错误消息:

The XML page cannot be displayed 
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. 
--------------------------------------------------------------------------------
A name was started with an invalid character. Error processing resource 'http://localhost/w/Service1.asmx'. Line 1, Positi...
<%@ WebService Language="C#" CodeBehind="Service1.asmx.cs" Class="WebService1.Service1" %>
-^

我查了这个文件:

Service1.asmx的

<%@ WebService Language="C#" CodeBehind="Service1.asmx.cs" Class="WebService1.Service1" %>

Service1.asmx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebService1
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
    }
}

有什么不好的?感谢您的支持。

2 个答案:

答案 0 :(得分:2)

看起来IIS机器上没有启用ASP.NET。

您可能需要检查Windows组件control panel -> Programs and Features -> Turn Windows features on or off并检查运行IIS的计算机上是否启用了Internet Information Services/World Wide Web Services/Application Development Features/ASP.NET功能,如果未启用则检查是否安装。

答案 1 :(得分:0)

。尝试在C:\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727中找到运行aspnet regiis utility命令  folder.Maybe脚本映射未正确更新。如果已经安装了IIS,安装.NET框架后是否安装了IIS?

  

aspnet_regiis -i

相关问题