C# 为什么我的web服务给我一个错误500?

C# 为什么我的web服务给我一个错误500?,c#,web-services,C#,Web Services,我有一个网络服务: using System.Web.Services; namespace Contracts { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] public class Second :

我有一个网络服务

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";
        }
    }
}
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"));
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">Contract 1</string>
以下WPF应用程序可以显示HTML精细文件:

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";
        }
    }
}
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"));
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">Contract 1</string>
但是当我用实际的web服务替换上面的行时

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";
        }
    }
}
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"));
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">Contract 1</string>
它给了我一个错误信息:

远程服务器返回了错误(500)内部服务器错误

虽然当我在浏览器中查看同一个URL时,我会看到XML文本精细

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";
        }
    }
}
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"));
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">Contract 1</string>

合同1

为什么它会给我500错误?返回HTTP代码500的服务通常意味着在请求处理过程中出现异常。如果将调试器连接到web服务器并正确配置,它将在异常时中断,您将能够看到它。此外,通常情况下,异常文本应包含在HTTP响应的正文中

在WCF服务上启用跟踪和日志记录以查看异常是什么(),或者按照前面的建议,在每个异常上附加带中断的调试器