How can I pass slash and other 'url sensitive' characters to a WCF REST service?

前端 未结 3 1385
灰色年华
灰色年华 2020-12-19 06:47

I have a REST WCF service that has a method that gets a parameter as a string. This string can contain slash / character. It makes my request wrong, as I think the URL goes

3条回答
  •  悲哀的现实
    2020-12-19 07:08

    I solved it.

    URI template is the key.

    If I define URI this way, it produces the exception above:

    [OperationContract()]
        [WebGet(UriTemplate = "/testmethod/{testvalue}"/*, BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml*/)]
        string TestMethod(string testvalue);
    

    By modifying this way, it works:

    [OperationContract()]
        [WebGet(UriTemplate = "/testmethod?v={testvalue}"/*, BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml*/)]
        string TestMethod(string testvalue);
    

    Anyway, Uri.EscapeDataString is needed!

提交回复
热议问题