2009-11-03 100 views
0

我有這個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錯誤?

回答

1

打開跟蹤並記錄您的WCF服務以查看異常情況(MSDN link)或將調試器在每個異常情況下都打破建議。 。

1

返回HTTP代碼500的服務通常意味着請求處理過程中出現異常。如果您有調試器連接到Web服務器並進行了正確配置,它將在異常時斷開並且您將能夠看到它。通常情況下,異常的文本應該包含在HTTP響應的主體中

相關問題