使用 GET 和 POST 使用服务

Consume Service with GET and POST

本文关键字:服务 POST GET 使用      更新时间:2023-09-26

我需要使用 GET AND POST ajaxcall 使用 WCF 服务。通过使用下面的代码,我可以实现 POST 方法,现在我想使用 GET 方法使用 wcf 服务。我需要在哪里更改代码。

.JS-

var para = { "ID": "87268" };
            $.ajax({
                url: 'http://localhost/Service/Review.svc/GetList',
                data: para,
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (result) { }
})

WCF服务-

[OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.WrappedRequest)]
        string GetList(int ID);

网络配置

<services>
  <service name="Service.Reviews" behaviorConfiguration="ServiceBehaviour">
    <endpoint address="" binding="webHttpBinding" contract="Service.IReviews" behaviorConfiguration="web">
    </endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

每个有"POST"的地方都需要更改为"GET",不是吗?