【问题标题】:WCF REST URIs ending in %20 fail with 404以 %20 结尾的 WCF REST URI 失败并出现 404
【发布时间】:2012-06-23 02:50:14
【问题描述】:

WCF REST Web 服务提供以下格式的查找:

https://mysite/mycontract/search/{searchtext}

hellohello%20world 的搜索文本,服务执行正确。但是,当使用 https://mysite/mycontract/search/hello%20 中以空格结尾的文本时,服务将失败并返回 404。没有自定义路由。

wcf 路由中的哪些限制会导致此问题,以及可用的解决方法(最好是更改 uri 结构除外)?

使用其他实施信息进行编辑:

合约

    [ServiceContract(SessionMode = SessionMode.NotAllowed)]
    public interface IPointOfSale
    {
        .......

        [WebInvoke(UriTemplate = "search/{SKU}", Method = "GET")]
        System.Xml.Linq.XElement ProductLookup(string SKU);

    }

方法

public XElement ProductLookup(string SKU)
{
   //product search here.
}

【问题讨论】:

  • 我无法在我的 WCF REST 服务中重现这一点(我在 URL 末尾正确地使用 %20 进行路由),你能提供一个例子吗?
  • @EkoostikMartin 我认为关键是它不在查询字符串中,而是在路线的末尾——你能看看这是否会影响你的结果吗?
  • 你是对的,我修改了我的 URI 看起来像你的,我得到了 404

标签: wcf c#-4.0 http-status-code-404 wcf-rest


【解决方案1】:

我今天一直在处理同样的问题,发现其他帖子告诉我们,在 .NET 4 中,解决方案在于在 web.config 中设置以下内容:

<httpRuntime relaxedUrlToFileSystemMapping="true" />

这为我解决了问题!

【讨论】:

    猜你喜欢
    • 2010-11-07
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    • 2011-09-19
    • 1970-01-01
    • 2012-01-27
    • 2018-10-17
    • 1970-01-01
    相关资源
    最近更新 更多