在RESTful wcf服务中调用post方法

时间:2011-12-24 11:33:55

标签: json post get wcf-rest

我正在制作一个GET方法,用链接调用它,一切正常。 这是:

    [OperationContract]
    [WebInvoke(
        Method = "GET",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json,
        UriTemplate = "/myMethod/{input}",
        BodyStyle = WebMessageBodyStyle.Bare
        )]
    MyClass myMethod(string input);

以下是我称之为的网址: http://localhost:1234/Service1.svc/json/myMethod/blabla

然而,当我制作一个post方法时,它不起作用。这是我的POST方法:

    [OperationContract]
    [WebInvoke(
        Method = "POST",
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Bare
        )]
    MyClass anotherMethod(string comeOn);

我用这个链接调用它: http://localhost:1234/Service1.svc/json/anotherMethod?comeOn=smthing 它说方法不允许。

如何调用POST方法?

2 个答案:

答案 0 :(得分:2)

好的,所以POST和GET之间的区别在于GET你在查询字符串上有所有参数,而POST在请求的消息体内有params。

http://wiki.answers.com/Q/What_is_the_difference_between_get_and_post_method_in_HTTP

你的第二个电话实际上正在进行GET,因此它不允许使用该方法。

可以在此处找到测试帖子的方法。

How to simulate browser HTTP POST request and capture result in C#

答案 1 :(得分:0)

以下是使用REST Web服务的MSDN链接。

http://msdn.microsoft.com/en-us/netframework/cc950529.aspx

相关问题