views:

98

answers:

2

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, DownloadStringCompletedEventArgs 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/"&gt;Contract 1</string>

Why is it giving me the 500 error?

A: 

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

mfeingold
+1  A: 

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. .

BennyM