在Windows 2008 R2 IIS 7.5上发布时,使用asmx的简单helloworld WebService无法正常工作

问题描述

我有一台运行IIS 7的Windows 2008 r2服务器(是的,这很旧,这对我来说可用)。它的网站在端口8080上运行。

我创建了一个空模板ASP.NET Web应用程序。然后我添加一个名为Phones.asmx的新项目

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Odbc;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Xml.Serialization;

namespace OSS_network
{
    /// <summary>
    /// Summary description for Phones
    /// </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 Phones : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public string Phonebook()
        {
            return "PhoneBook";
        }
    }
}

然后,我将其发布到一个文件夹,该文件夹中的内容已复制到Win2008服务器上的文件夹中。在IIS中,我在端口8080上创建了一个新网站,并创建了链接到发布文件所在文件夹的路径。

我能够从本地计算机(服务器本身)连接到Phones.asmx并查看方法调用它们。

然后,我尝试成功连接到Phones.asmx。我可以看到定义的WebMethod,

enter image description here

但是

当我尝试调用方法时,出现以下错误

enter image description here

有人可以帮助解决错误吗?一定很简单。

解决方法

我之所以有答案,是因为我的撒玛利亚人在上一个问题中回答了这个问题,该问题由于信息不足而被关闭。

我使用下面的代码行来解决此问题。在web.config文件中编写以下代码。

<configuration>
    <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>

希望这可以帮助下一个遇到麻烦的人,如我的。