views:

2642

answers:

2

Hello all,

I borrowed the following code to try to make an ajax-enabled WCF service work since I kept getting the 405 method not allowed error:

$('#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);
            }
        });

In the service code-behind I have the following:

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

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

I have seen searched up & down the net all day today trying to find what the issue could be...I have seen posts where .svc isn't mapped with the POST verb in IIS...it isn't on my dev pc but it is on the server. Both give the 405 errors...

Could this have something to do with the verbs being allowed in the web.config?

I have a beautiful site going so far & having this work (and soon) will really make a good impression, please help!!!

Thanks!!!

+1  A: 

Do you have this line inside your web.config service model?

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
</serviceHostingEnvironment>
REA_ANDREW
Yes this is set to true...
wali
+1  A: 

You need to add this attribute to your method:

ScriptMethodAttribute
Otávio Décio
wali