【发布时间】:2011-09-05 16:46:30
【问题描述】:
我是 .NET 的新手。现在我正在尝试制作我的第一个 ASP.NET Web 服务。
我创建 ASP.NET Web 服务项目并使用 Visual Studio 2010 生成的默认 Web 方法。
我在 Visual Studio 中测试过这个服务,效果很好。
然后我在 IIS 上添加了虚拟目录,目录名为 test。我使用的是 Windows Server 2003 标准版。
并尝试通过 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";
}
}
}
有什么不好的?感谢支持。
【问题讨论】:
-
检查您的
test虚拟目录中选择的asp.net 版本,它将是2.0.50727。 -
这不是您问题的答案,但我会考虑使用 WCF 服务而不是经典的 asmx Web 服务。
-
您不应该将 ASMX 服务用于新开发。微软现在认为它们是“遗留技术”。 WCF 应该用于所有新的服务和客户端开发。
标签: c# asp.net xml web-services iis