【发布时间】:2011-12-24 11:33:55
【问题描述】:
我正在制作一个 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 方法?
【问题讨论】:
-
这是一个重复的问题吗? stackoverflow.com/questions/1144166/…
-
@TomislavMarkovski 不,我只是要网址。
-
如果您要求提供 URL,则表示您正在获取方法。您不能通过请求 URL 来发布。
-
您需要为此提供一个 UI。您可以为此创建一个 Web 表单或客户端应用程序。
-
Да, така некако,但您仍然可以将参数从您的网页或客户端应用程序传递给您正在调用的方法。