【问题标题】:Colon : in a REST WCF Request冒号:在 REST WCF 请求中
【发布时间】:2012-06-06 10:04:30
【问题描述】:

所以我有一个指向我的 wcf 服务的 URL,如下所示:

http://dev.verse-master.com/api/VerseMasterService.svc/Search/bi/isaiah 34:16/0/60

我的运营合同是这样的:

[OperationContract]
[WebGet(UriTemplate = "/Search/{translation}/{searchTerm}/{skip}/{take}", ResponseFormat = WebMessageFormat.Json)]
VerseMaster.BusinessLayer.DataObjects.ServerObjects.GetVersesSearchServerObject GetVersesBySearch(string translation, string searchTerm, string skip, string take);

我已经尝试通过在线阅读将此行添加到 web.config:

<httpRuntime requestPathInvalidCharacters="" requestValidationMode="4.0"/>

但我仍然收到此错误:

HTTP 错误 400 - 错误请求。

有什么想法吗?

【问题讨论】:

    标签: wcf rest colon


    【解决方案1】:

    对url进行编码应该没问题,返回时处理即可。这也将有助于反斜杠,这将导致与 :

    相同数量的问题

    例如

    调用服务:

    String encodedSearchTerm = Server.UrlEncode(searchTerm);
    String UrlToCall = String.Format("{0}{1}{2}","http://dev.verse-master.com/api/VerseMasterService.svc/Search/bi/",encodedSearchTerm,"/0/60");
    

    ...等等...

    那么在你的操作中:

    [WebGet(UriTemplate = "/Search/{translation}/{searchTerm}/{skip}/{take}", ResponseFormat = WebMessageFormat.Json)] 
    VerseMaster.BusinessLayer.DataObjects.ServerObjects.GetVersesSearchServerObject GetVersesBySearch(string translation, string searchTerm, string skip, string take){
    ...etc...
    String DecodedSearchTerm= Server.UrlDecode(searchTerm);
    ...etc...
    }
    

    记住需要导入System.Web

    【讨论】:

    • 当然可以,但是如何运行 wcf 服务并允许冒号
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    • 2014-09-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 2023-03-10
    • 2011-09-29
    相关资源
    最近更新 更多