0

我有一个 wcf REST 服务,它正在调用一个更新数据库中某些内容的方法。该方法接受一个参数。

让我说我是void MarkMobileAppApplicationAsCancelled(string applicationId);

现在我正在尝试使用来自 chrome 应用商店的一个名为 CREST 的应用来调用该服务。但我不知道如何以 Json 格式调用该方法。

有什么帮助吗??

我有类似的东西

[OperationContract]
        [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/MarkMobileAppApplicationAsConfirmed/")]
        void MarkMobileAppApplicationAsConfirmed(string applicationId);

我正在尝试初始化此方法,该方法将通过设置应用程序的 application_confirmed = true 来更新我的数据库,

我在请求生成器中写了以下内容

https://local.blaSys.com/MobileAppWCF.svc/MarkMobileAppApplicationAsCancelled/

以及标题中的以下内容

content-type:application/json

现在,我会在请求实体中写什么?

4

1 回答 1

1

很可能你不想在请求中写任何东西,而是applicationID从 url 中获取。

您可以通过稍作修改来获得它

    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/MarkMobileAppApplicationAsConfirmed/{applicationID}")]
    void MarkMobileAppApplicationAsConfirmed(string applicationId);

Now you can simply make a standard http request (using curl/fiddler for testing and WebClient/WebRequest) in the proxy against the endpoint

https://local.blaSys.com/MobileAppWCF.svc/MarkMobileAppApplicationAsCancelled/someApplicationId

Remember that the method given to the request must be POST as indicated in the WebInvoke attribute. (I guess a PUT would be more idiomatically correct since you must be updating a method, but that is another discussion.)

Hope this helps!

于 2012-11-16T13:03:59.463 回答