![](/img/trans.png)
[英]How to self-host a WCF REST XML Service over https without using app.config?
[英]WCF REST Service - Self Host Windows Service - How to use % in URL
我有一個REST WCF服務,該服務具有一種將參數作為字符串獲取的方法
當我在網址中使用%23時,出現錯誤消息:找不到端點! 例如:
-- 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 Service上托管了WCF,所以它不起作用
由於此線程,我找到了解決方案:
如何將斜杠和其他“ URL敏感”字符傳遞給WCF REST服務?
解:
<configuration>
<system.net>
<settings>
<httpListener unescapeRequestUrl="false"/>
</settings>
</system.net>
</configuration>
在網址中使用一些特殊字符不是最好的做法。 請考慮不要使用它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.