繁体   English   中英

使用 asmx 的简单 helloworld WebService 在 Windows 2008 R2 IIS 7.5 上发布时不起作用

[英]Simple helloworld WebService using asmx not working when published on Windows 2008 R2 IIS 7.5

我有一台运行 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,这是成功的。 我可以看到定义的 WebMethods, 在此处输入图片说明

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

在此处输入图片说明

有人可以帮忙解决这个错误吗? 这一定是一些简单的事情。

我有答案,因为我的好撒玛利亚人在我的最后一个问题中回答了这个问题,但由于信息不足而被关闭。

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

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

希望这能帮助下一个像我一样遇到麻烦的人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM