【问题标题】:Visualstudio generated Webservice throws exception (no code written yet)Visual Studio 生成的 Web 服务引发异常(尚未编写代码)
【发布时间】:2017-07-23 08:16:15
【问题描述】:

一个新的、空的 Visualstudio 项目,只有自动生成的代码,在尝试从该 web 服务自己的描述页面调用 web 服务时引发异常。

我有一个奇怪的问题,我投影,工作正常,当我上次使用它时,当我在 2 个月后打开它时突然停止工作(两者之间没有变化)。我无法弄清楚原因是什么,所以我尝试以更简单的方式重新创建它。

这是一个不起作用的示例,没有一行手写代码,全部由 visualstudio 创建。

这是我为重现问题所做的。

我使用 Visualstudio 2015 我创建了一个新项目 -> Web -> ASP.NET -> Web API。 我添加了一个名为“服务”的空文件夹 我右键单击文件夹->添加->(Webservice Asmx)

创建了一个新的演示页面:

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

namespace ProjektName.Services
{
    /// <summary>

    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    // [System.Web.Script.Services.ScriptService]
    public class getUrl : System.Web.Services.WebService
    {

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

当我开始调用页面时,Webservice 自我描述页面打开。

这些不是实际的屏幕截图,因为我的 Visual Studio 使用的是不同的语言。 (它们只是用来解释我的观点)。

我使用 Windows 10 并使用最新的 Chrome 和 firefox 浏览器。 /HelloWorld_files/image004.jpg

现在,当我点击按钮时,我收到“'/' 应用程序中的服务器错误”。 “找不到资源。”

错误消息如下所示: https://www.1and1.com/cloud-community/fileadmin/community/Screenshots/How_to_Fix_the_Error_in_application_Windows_Server_error/404.jpg

我没有写过任何代码,都是由 Visal Studio 生成的。 如果我将项目交给同事,他的电脑也无法运行。

我错过了什么?

【问题讨论】:

  • “这些不是实际的屏幕截图”是个问题。魔鬼在细节中。
  • asmx 是一种方式,远远超出了它的生命周期。改为投资 WebAPI 或 WCF。
  • WebAPI 不起作用,所以我切换到 ASMX
  • “所以我切换了......” - 现在你有 2 个问题(-:说真的,ASMX 是生命终结的东西,算了吧。
  • 您的解决方案有效,谢谢,现在只剩下一个问题^^ :) 谢谢。

标签: asp.net web-services asp.net-web-api asmx


【解决方案1】:

添加忽略规则:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.IgnoreRoute("Services/{resource}.asmx/{*pathInfo}");  // add this line

    ....
}

但看起来你正在做一些“教程”。您确定要投资 ASMX 技术吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多