【问题标题】:WCF Restful service not sending response to web clientWCF Restful 服务未向 Web 客户端发送响应
【发布时间】:2014-02-04 12:26:08
【问题描述】:

我在我的 Web 应用程序中使用 MVC5、WebAPI、WCF Restful 服务。

当我朗姆酒 WCF 宁静的服务时,我得到了不同的反应。有些服务给了我适当的回应,有些没有。我正在我的机器上运行这个应用程序。

我使用 Fiddler 调试服务。

成功:

localhost/UserRestService.svc/api/GetMembership/23

失败: localhost/UserRestService.svc/api/GetUserProfile/xyz@gmail.com

错误:[Fiddler] ReadResponse() 失败:服务器没有返回一个 对此请求的响应。服务器返回 0 个字节。

我无法理解这个错误。我用谷歌搜索并无法解决此错误。

请帮忙。

代码:

WCF 服务接口:

    [OperationContract]
    [WebGet(UriTemplate = "/api/GetUserProfile/{userName}",RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    // UserProfiles 
    UserProfile GetUserProfile(string userName);

提琴手原始请求

GET localhost:37181/UserRestService.svc/api/GetUserProfile/abc@gmail.com HTTP/1.1
Host: localhost:37181
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Cookie: _gauges_unique_year=1; _gauges_unique=1; lang=auto; __RequestVerificationToken=XCXv18_vpGu9UO4wian60eLRZqUQi6_

【问题讨论】:

  • 如果在服务代码中设置断点会发生什么?服务是否被调用?另外,看到了这个:stackoverflow.com/questions/9425288/…
  • @rmayer06:当我在服务上放置断点时,它会给出适当的响应。但最后,浏览器向我显示了上述错误。
  • @Zaki:我已经添加了代码...
  • 在您的服务和返回 Web 服务之间发生了一些事情。也许是序列化错误?您是否有 MS 源代码,您可以在代码之后单步执行代码吗?

标签: c# asp.net wcf rest asp.net-web-api


【解决方案1】:

您需要转义 @ 符号,它在 URI 中具有保留的含义。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-10
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    相关资源
    最近更新 更多