2012-06-20 25 views
1

一個WCF REST Web服務結束提供了格式查找:WCF REST的URI在%20失敗,404

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

你好,或你好%20world的搜索文本,以及服務正確執行。但是,如果使用https:// mysite/mycontract/search/hello%20中的以空格結尾的文本,則服務將失敗並顯示404。沒有自定義路由。

wcf routing有什麼限制會導致這種情況,以及哪些解決方法(理想情況下除了更改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. 
} 
+0

我無法在我的WCF REST服務中重現此操作(我正確路由到URL末尾的%20),您能提供一個示例嗎? – EkoostikMartin

+0

@EkoostikMartin我認爲關鍵在於它不在查詢字符串中,而是在路由的末尾 - 您能否看到這是否會影響您的結果? – seraphym

+0

你是對的,我修改我的URI看起來像你的,我得到了404 – EkoostikMartin

回答

1

我有同樣的問題今天已經工作,並發現了其他帖子講在.NET 4中,解決方案在於在web.config中設置以下內容:

<httpRuntime relaxedUrlToFileSystemMapping="true" /> 

這解決了我的問題!