2012-03-16 95 views
2

在基於IIS中的基於WCF Rest的服務中,出現以下問題。WCF REST和IIS Express 7.5返回請求錯誤(400)

接口:

[ServiceContract] 
public interface ITestService 
{ 
    [OperationContract] 
    [WebInvoke(Method = "GET", UriTemplate = "/GetEmployee/{userid}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Bare)] 
    IEnumerable<Employee> GetPlans(string userid); 
} 

TestService.svc.cs:

public class TestService : ITestService 
{ 
    public IEnumerable<Employee> GetEmployee(string userid) 
    {  
     return Employee 
    } 
} 

當我使用卡西尼服務器,它工作在JSON格式精細returnштп結果。網址如下:

http://localhost:58764/TestService/TestService.svc/GetEmployee/2 

但是當我主持,在IIS快遞7.5在URL:

http://localhost/TestService/TestService.svc/GetEmployee/2) 

它只是說:

「請求錯誤

服務器在處理請求時遇到錯誤,請參閱服務幫助頁面,以便爲服務構建有效的請求。「

http://localhost/TestService/TestService.svc/help 

返回所有可用的方法沒有任何問題的URL。

+0

您確定Employee對象是可序列化的嗎?有時通過cassini的序列化通過,但在IIS上託管時失敗。在IIS上託管時,請嘗試在您的服務上啓用跟蹤,以獲取您的請求失敗原因的確切原因。可能是由於返回的數據大小所致 – Rajesh 2012-03-16 09:00:22

回答

0

不確定這個問題。

你可以嘗試重新安裝.net框架嗎?

  • 打開Visual Studio 2010命令提示符
  • 類型 「ASPNET_REGIIS -i」,然後按回車
  • 重新啓動IIS如果IIS安裝WCF組件具有

  • 檢查。如果沒有安裝。以下命令,然後重新啓動

  • 運行IIS C:\ WINDOWS \ Microsoft.NET \框架\ 3.0 \ Windows通信基礎>服務 ModelReg.exe -i

之後嘗試。希望它能工作,我有類似的問題,這些步驟後解決。

+0

謝謝Shailesh。我嘗試了這些步驟,但問題仍然存在。之後,我嘗試了SVCTraceViewer.exe,發現問題是因爲模仿問題。最後我解決了它。 – Naveen 2012-03-19 07:36:09