开发者

Why is my web service giving me an Error 500?

开发者 https://www.devze.com 2022-12-09 22:51 出处:网络
I have this web service: using System.Web.Services; namespace Contracts { [WebService(Namespace = \"http://tempuri.org/\")]

I have this web service:

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";
        }
    }
}

The following WPF application can display the HTML fine:

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, DownloadS开发者_运维技巧tringCompletedEventArgs e)
        {
            Message.Text = e.Result.ToString();
        }
    }
}

but when I replace the above line with the actual web service:

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

it gives me the error message:

The remote server returned the error (500) Internal Server Error.

Although when I look at the same URL in my browser, I see the XML text fine:

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

Why is it giving me the 500 error?


Turn on tracing and logging on your WCF service to see what the exception is (MSDN link) or attach the debugger with break on every exception as already suggested. .


The service returning HTTP code 500 usually means that there was an exception during request processing. If you have debugger attached to the web server and configured properly it will break on exception and you will be able to see it. Also usually the text of the exception should be included in the body of the HTTP response

0

精彩评论

暂无评论...
验证码 换一张
取 消