简体   繁体   English

使用WCF的简单REST服务

[英]Simple REST service with WCF

I'm trying to make a simple REST service in VS2010 (.NET 4) with one method that receives three string parameters. 我正在尝试使用一种接收三个字符串参数的方法在VS2010(.NET 4)中制作一个简单的REST服务。 I want it to be accessed using both GET and POST (because 3'rd param could be quite big sometimes) 我希望同时使用GET和POST来访问它(因为第3个参数有时可能很大)

In class MyREST.cs I have this code 在MyREST.cs类中,我有这段代码

    [WebGet(UriTemplate = "s={s}&sp={sp}&p={p}")]
    public string Process(string s, string sp, string p)
    {
        // some processing
        return result;
    }

Same for POST 与POST相同

When I try to access the service with an url like 当我尝试使用以下网址访问服务时

http://localhost:57129/OneTestREST/s=str1&sp=str2&p=str3

I get error 我得到错误

Exception Details: System.Web.HttpException: A potentially dangerous Request.Path value was detected from the client (&). 异常详细信息:System.Web.HttpException:从客户端(&)检测到潜在危险的Request.Path值。

If I change the attribute to 如果我将属性更改为

[WebGet(UriTemplate = "/{s}/{sp}/{p}")]

It works ok. 可以。 But I would like to access it with first syntax 但是我想用第一种语法访问它

Any idea why is this happening? 知道为什么会这样吗?

Thank you 谢谢

[WebGet]
public string Process(string s, string sp, string p)
{
    // some processing
    return result;
}

then 然后

http://localhost:57129/OneTestREST/?s=str1&sp=str2&p=str3

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

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