【发布时间】: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