有人能发现这个实现的问题吗?我可以在浏览器中打开它并且它可以工作,但是来自客户端的调用(同时使用jquery和asp.net ajax失败)
服务合同@H_301_3@
[OperationContract(Name = "GetTestString")] [WebInvoke(Method = "GET",ResponseFormat = WebMessageFormat.Json )] string GetTestString();
在Web.config和其他绑定之间,我有一个webHttp绑定@H_301_3@
<endpoint address="ajax" binding="webHttpBinding" contract="TestService" behaviorConfiguration="AjaxBehavior" />
终点行为@H_301_3@
<endpointBehaviors> <behavior name="AjaxBehavior"> <enableWebScript/> </behavior> </endpointBehaviors> </behaviors>
<%@ ServiceHost Service="TestService" %>
客户@H_301_3@
var serviceUrl = "http://127.0.0.1/Test.svc/ajax/"; var proxy = new ServiceProxy(serviceUrl);
然后我在http://www.west-wind.com/weblog/posts/324917.aspx中使用该方法
打电话给服务@H_301_3@
解决方法
链接上的示例使用Http POST,而不是Http GET.那是“不允许的方法” – 你需要改变代码来代替GET.
您发布的链接是您的客户端代码的源代码具有以下块:@H_301_3@
$.ajax( { url: url,data: json,type: "POST",processData: false,contentType: "application/json",timeout: 10000,dataType: "text",// not "json" we'll parse
注意类型:“POST”在那里 – 你的需要是“GET”.我假设你从你发布的链接中获取了你的JQuery,因为405状态表明你的调用代码是错误的,而不是服务.@H_301_3@