2012-04-20 172 views
0

我有一個名爲「WebMethods」的WCF服務。以下是我的代碼。WCF Web服務不工作

在IWebMethods.cs:

[ServiceContract(Name = "WebMethods")] 
public interface IWebMethods 
{ 
    [OperationContract] 
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] 
    String Test(); 
} 

在WebMethods.cs:

public class WebMethods : IWebMethods 
{ 
    public String Test() 
    { 
     return "This is a test YEAH!!"; 
    } 
} 

和調用的javascript:

$.ajax({ 
     url: 'WebMethods.svc/Test', 
     type: "POST", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     data: null, 
     async: false, 
     success: function (data) { 
      alert(data); 
     }, 
     error: function (xhr, textStatus, errorThrown) { 
      alert(errorThrown); 
     } 
    }); 

當我執行我的javascript我得到的錯誤「內部服務器錯誤」。有人可以告訴我我做錯了什麼,或者至少我能做些什麼來解決這個問題?

+0

您能提供比'內部服務器錯誤'更多的日誌嗎? – fmgp 2012-04-20 17:35:45

+0

@fmgp,這是服務返回的唯一錯誤。有什麼地方可以查找更詳細的錯誤消息嗎? – Coltech 2012-04-20 17:37:39

+0

您可以直接導航到您的服務頁面嗎? – 2012-04-20 17:49:37

回答

3

你的web.config文件怎麼樣?嘗試導航到您的服務頁面,也許它可以給你更多關於錯誤的解釋。上面的代碼似乎沒問題。