【问题标题】:WCF REST and IIS Express 7.5 returns Request Error (400)WCF REST 和 IIS Express 7.5 返回请求错误 (400)
【发布时间】:2012-03-16 05:16:41
【问题描述】:

我对在 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);
}

TestService.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

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

【问题讨论】:

  • 您确定对象 Employee 是可序列化的。有时通过 cassini 的序列化通过但在 IIS 上托管时失败。还可以尝试在托管在 IIS 上时对您的服务启用跟踪,以了解您的请求失败的确切原因。也可能是由于返回的数据的大小

标签: .net wcf iis-express http-status-code-400


【解决方案1】:

不确定这个问题。

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

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

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

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

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

【讨论】:

  • 谢谢Shailesh。我尝试了这些步骤,但问题仍然存在。之后我尝试使用 SVCTraceViewer.exe 并发现问题是因为模拟问题。最后我解决了。
猜你喜欢
  • 2017-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-24
  • 2014-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多