【问题标题】:Consume Service with GET and POST使用 GET 和 POST 使用服务
【发布时间】:2014-11-20 12:00:13
【问题描述】:

我需要使用 GET 和 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);

WEB.CONFIG

<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" />

【问题讨论】:

  • 看看这篇文章。我相信它应该会给你一个答案stackoverflow.com/questions/555073/…
  • 请注意,您不能通过 get 将 json 发送到 Web 服务,您只能发送查询字符串参数。

标签: javascript c# jquery web-services wcf


【解决方案1】:

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

【讨论】:

  • 我已经尝试过了,但仍然没有得到正确的响应。
猜你喜欢
  • 2014-03-01
  • 2017-04-06
  • 1970-01-01
  • 2013-10-08
  • 2019-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多