0

I have seen a few other posts with this error, but I have tried everything suggested in those and am still having an issue.

Here is my webMethod (and class):

<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class UPSImportWebServices
    Inherits System.Web.Services.WebService

    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    <WebMethod()> _
    Public Shared Function GetInvoiceItems(ByVal invoiceId As Integer) As List(Of UPSInvoiceItem)
        Return UPSInvoiceDataAccess.getInvoiceItems(invoiceId)
    End Function

End Class

I just call this on document ready:

$(document).ready(function () {
    $.ajax({
        type: "POST",
        url: '<%=ResolveUrl("~/UPSImportWebServices.asmx/GetInvoiceItems") %>',
        data: { invoiceID: "22" },
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            alert('worked' + data)
        },
        error: function (response) {
            alert('error: ' + response.responseText);
        },
        failure: function (response) {
            alert('failure: ' + response.responseText);
        }
    });
});

This gives me the error: Unknown web method GetInvoiceItems. Parameter name: methodname.

EDIT: Changed invoiceID: "22" to invoiceID: 22. Still having the same issue.

3 Answers 3

2

I think I figured out the issue. I had copied an existing .asmx file rather than creating a new one. When I went to the url site.com/UPSImportWebServices.asmx, it showed the functions for the web service I copied. I deleted that .asmx file and created a new one and then copied my old code. It is working now.

Also, changed to '{ invoiceId:' + 22 + '}'. Note the ' and the capitalization. Rookie mistakes on this one.

Sign up to request clarification or add additional context in comments.

1 Comment

Use JSON.stringify instead of manually constructing a JSON string; it's cleaner and modular.
1

Well, i think this might have to do with the type of variable you are passing. GetInvoiceItems is expecting an integer, you are passing it a string. Try doing changing this

data: { invoiceID: "22" },

to this:

data: { invoiceID: 22 },

and let me know if that works or not. If not, we can move to the next possibility.

Try changing this:

url: '<%=ResolveUrl("~/UPSImportWebServices.asmx/GetInvoiceItems") %>',

to this:

 url: 'UPSImportWebServices.asmx/GetInvoiceItems',

and make sure the spelling of your asmx file is correct (case sensitive)

and lastly, try making your method just Public, not Public Shared.

5 Comments

Good catch. I made that change, but am still having the same issue.
I edited my response to try a few more things. let me know if it still fails
Thanks again, but still having the same issue after making those additional changes.
Do you know how to use the web console in FireFox? This should show you an error. Run your app with the console open and let me know what the error is.
I think I figured out the issue. I had copied an existing .asmx file rather than creating a new one. When I went to the url site.com/UPSImportWebServices.asmx, it showed the functions for the web service I copied. I deleted that .asmx file and created a new one and then copied my old code. It is working now. Thanks for the help and sorry for having wasted your time.
1

Try doing this.

data: JSON.stringify({ invoiceId: 22 })

The webservice expects a JSON string.

Also, parameters are case sensitive. Your "D" in "invoiceID" is capitalized whereas the web method expects it to be "invoiceId" (lowercase d).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.