405 Method Not Allowed Error in WCF

前端 未结 2 491
忘了有多久
忘了有多久 2020-12-11 22:17

Can someone spot the problem with this implementation? I can open it up in the browser and it works, but a call from client side (using both jquery and asp.net ajax fails)

相关标签:
2条回答
  • 2020-12-11 22:38

    for method not allowed error, all you need to check is to make sure that your http web call /request is the same as the one specified in [WebInvoke...] in the service

      $.ajax({
                    type: "POST",.....});
    

    SHOULD BE IDENTICAL TO WHAT WAS SPECIFIED IN THE SERVICE INTERFACE (UNDER "[Operation Contract]")

     [WebInvoke(Method = "POST",BodyStyle = WebMessageBodyStyle.Wrapped,ResponseFormat = WebMessageFormat.Json)]
    
    0 讨论(0)
  • 2020-12-11 22:54

    The example on your link uses a Http POST, not a Http GET. That's the "method [that's] not allowed" - you need to change the code to do a GET instead.

    The link you post that was your source for client code has this block:

     $.ajax( { 
                    url: url,
                    data: json,
                    type: "POST",
                    processData: false,
                    contentType: "application/json",
                    timeout: 10000,
                    dataType: "text",  // not "json" we'll parse
    

    Note the type: "POST" in there - yours would need to be "GET". I'm assuming you've taken your JQuery from the link you posted, because the 405 status suggests that your calling code is wrong, not the service.

    0 讨论(0)
提交回复
热议问题