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