2016-12-29 204 views
0

我有有獲得一個參數爲一個字符串WCF REST服務 - 自主機Windows服務 - 如何使用%的URL

當我在我的URL中使用的%23的方法的REST WCF服務錯誤消息:未找到端點! 如:

-- Id #9999 
http://localhost:8000/MyService/GetData/Id/%239999 (%23 means # symbol encoded) 

如果我沒有使用象徵%正常工作

http://localhost:8000/MyService/GetData/Id/10 

[ServiceContract] 
public interface IService1 
{ 
    [OperationContract] 
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetData/id/{id}")] 
    string GetData(string value); 

} 

我的主機服務的Windows服務:

 ServiceHost host = new ServiceHost(typeof(Service1), "http://localhost:8000"); 

     WebHttpBinding binding = new WebHttpBinding(); 

     ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IService1), binding, "MyService"); 
     WebHttpBehavior httpBehavior = new WebHttpBehavior();   
     endpoint.Behaviors.Add(httpBehavior); 

     host.Open(); 

我發現這個帖子: http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx但它不起作用,因爲我沒有在IIS上託管WCF我將它託管在Windows服務上而不是

回答

0

它不是一個最好的初步實踐使用一些特殊字符的URL中。請考慮不要使用它們。

看看MSDN - UriTemplate

+0

感謝保羅,但問題是我們在標識特殊字符。他們在這裏使用這種方式,我必須遵循。 – Rick