【问题标题】:Why is my web service giving me an Error 500?为什么我的 Web 服务给我一个错误 500?
【发布时间】:2009-11-03 21:19:06
【问题描述】:

我有这个网络服务

using System.Web.Services;

namespace Contracts
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class Second : System.Web.Services.WebService
    {
        [WebMethod]
        public string GetContract()
        {
            return "Contract 1";
        }
    }
}

以下 WPF 应用程序可以很好地显示 HTML

using System.Windows;
using System.Net;
using System;

namespace TestConsume2343
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            WebClient proxy = new WebClient();
            proxy.DownloadStringCompleted += new DownloadStringCompletedEventHandler(proxy_DownloadStringCompleted);
            proxy.DownloadStringAsync(new Uri("http://localhost:57379/Second.asmx?op=GetContract"));
            Message.Text = "loading...";

        }

        void proxy_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            Message.Text = e.Result.ToString();
        }
    }
}

但是当我用 实际的网络服务替换上面的行时:

proxy.DownloadStringAsync(new Uri("http://localhost:57379/Second.asmx/GetContract"));

它给了我错误消息:

远程服务器返回错误 (500) Internal Server Error。

虽然当我在浏览器中查看相同的 URL 时,我看到了 XML 文本 fine:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">Contract 1</string>

为什么会出现 500 错误?

【问题讨论】:

    标签: c# web-services


    【解决方案1】:

    在您的 WCF 服务上打开跟踪和日志记录以查看异常是什么 (MSDN link),或者按照已经建议的在每个异常上附加带有中断的调试器。 .

    【讨论】:

      【解决方案2】:

      服务返回 HTTP 代码 500 通常表示请求处理过程中出现异常。如果您将调试器附加到 Web 服务器并正确配置,它将在异常时中断,您将能够看到它。通常异常的文本应该包含在 HTTP 响应的正文中

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-08
        • 2013-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-09
        相关资源
        最近更新 更多