简体   繁体   English

当url段为json字符串时,在访问WCF Rest服务(WebGet)时未找到404

[英]Not found 404 while accessing WCF Rest service (WebGet) when url segment is json string

In my project i have to pass dynamic Json string to WCF Rest service web get. 在我的项目中,我必须将动态Json字符串传递给WCF Rest服务web get。

when i pass some string as below everything works fine. 当我传递一些字符串,如下所示一切正常。

http://localhost:58014/MyService.svc/api/queries/somestirng HTTP://本地主机:58014 / MyService.svc / API /查询/ somestirng

but when i pass json string as url segment not found error occurs. 但当我传递json字符串作为url段未找到错误发生。

{"Key":"UserHomePageInfoQuery","Message":"{\\"UserName\\":\\"usr83\\"}"} { “密钥”: “UserHomePageInfoQuery”, “消息”: “{\\” 用户名\\ “:\\” usr83 \\ “}”}

http://localhost:58014/MyService.svc/api/queries/257b%2522Key%2522%253a%2522UserHomePageInfoQuery%2522%252c%2522Message%2522%253a%2522%257b%255c%2522UserName%255c%2522%253a%255c%2522usr83%255c%2522%257d%2522%257d HTTP://本地主机:58014 / MyService.svc / API /查询/ 257B%2522Key%2522%253A%2522UserHomePageInfoQuery%2522%252℃%2522Message%2522%253A%2522%257B%255℃%2522UserName%255℃%2522%253A% 255C%2522usr83%255C%2522%257D%2522%257D

Here is my service operation contract definition 这是我的服务运营合同定义

    [OperationContract]
    [WebGet(UriTemplate = "api/queries/{queryString}",                        
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json)]
    Response Query(string queryString);

I know i can use POST, but all requests to service is query 我知道我可以使用POST,但所有服务请求都是查询

I have another service for commands by POST 我通过POST为命令提供了另一项服务

[OperationContract]
        [WebInvoke(UriTemplate = "api/commands/",
            Method = "POST",            
            RequestFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json)]       
        Response Execute(Request request)

I use a wildcard (*) in the {queryString} parameter, which means "the rest of the URI" 我在{queryString}参数中使用通配符(*),这意味着“URI的其余部分”

https://msdn.microsoft.com/en-us/library/bb675245.aspx https://msdn.microsoft.com/en-us/library/bb675245.aspx

    [OperationContract]
    [WebGet(UriTemplate = "api/queries/{*queryString}",                        
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json)]
    Response Query(string queryString);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM