我有這個Web服務:爲什麼我的web服務給我一個錯誤500?
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();
}
}
}
但是當我更換了與實際的Web服務上面的行:
proxy.DownloadStringAsync(new Uri("http://localhost:57379/Second.asmx/GetContract"));
它給了我錯誤消息:
遠程服務器返回錯誤(500)內部服務器錯誤。
雖然當我在看相同的URL在瀏覽器中,我看到的XML文本精細:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">Contract 1</string>
爲什麼給我500錯誤?