2009-02-26 64 views
2

我借下面的代码,试图使支持AJAX的WCF服务工作,因为我一直得到405方法不被允许错误:405方法试图发布到Web服务时不允许错误

$('#btnSave').click(function (e) { 
    $.ajax({ 
    type: "POST", 
    url: "AjaxWcf.svc/ConnectionTest", 
    contentType: "application/json; charset=utf-8", 
    data: '{"name":"Elemenex"}', 
    dataType: "json", 
    success: function (msg) { 
     alert(msg.d); 
    }, 
    error: AjaxFailed 
    }); 

    function AjaxFailed(result) { 
    alert(result.status + ' ' + result.statusText); 
    } 
}); 

在服务代码隐藏我有以下几点:

<OperationContract()> _ 
<WebInvoke(Method:="POST")> _ 

Public Function ConnectionTest(ByVal name As String) As String 
    Return String.Format("Hello {0}", name) 
End Function 

我已经看到了搜索下来&净今天一天都试图找到这个问题可能是什么。我已经看到帖子,其中.svc未与IIS中的POST动词映射。它不在我的开发PC上,但它在服务器上。两者都给出了405个错误。

这可能与web.config允许的动词有关吗?

我有一个漂亮的网站,迄今为止&有这项工作(并很快)将真正留下好印象。

谢谢!

回答

1

您需要将此属性添加到您的方法:

ScriptMethodAttribute 
+0

这是该示例及与一些调整的工作也是我需要的东西的工作以及... – wali 2009-02-27 00:22:03

1

你的web.config服务模式中是否有这条线?

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"> 
</serviceHostingEnvironment> 
+0

是的,这是设置为true ... – wali 2009-02-26 21:09:44

相关问题