2

我对在 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

返回所有可用的方法,没有任何问题。

4

1 回答 1

0

不确定这个问题。

您可以尝试重新安装.net 框架吗?

  • 打开 Visual Studio 2010 命令提示符
  • 输入“aspnet_regiis -i”并按回车
  • 重新启动 IIS

  • 检查 IIS 是否安装了 WCF 组件。如果没有安装。

  • 运行以下命令并重新启动 IIS C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation>Service ModelReg.exe -i

之后试试。希望它应该可以工作,在这些步骤之后我遇到了类似的问题。

于 2012-03-16T05:41:25.227 回答