我对在 IIS 中托管基于 WCF Rest 的服务的以下问题感到震惊。
界面:
[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);
}
测试服务.svc.cs:
public class TestService : ITestService
{
public IEnumerable<Employee> GetEmployee(string userid)
{
return Employee
}
}
当我使用 Cassini 服务器时,它可以正常工作以 json 格式返回штп 结果。网址如下:
http://localhost:58764/TestService/TestService.svc/GetEmployee/2
但是当我在 IIS Express 7.5 中的 URL 上托管它时:
http://localhost/TestService/TestService.svc/GetEmployee/2)
它只是说:
“请求错误
服务器在处理请求时遇到错误。请参阅服务帮助页面以构建对服务的有效请求。”
但网址在
http://localhost/TestService/TestService.svc/help
返回所有可用的方法,没有任何问题。