0

I have a site which uses WebForms. It has a service which used to work, but my host recently migrated the site to a new server. The DB connections are working but my asmx service is now broken.

I have this signature:

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public string GetJarLabel(string type, string serialized)
{

Which I'm calling with this jQuery:

var requestData = {
            "type":  "jam",
            "serialized": JSON.stringify(data)
};
$.ajax({
            type: "POST",
            url: "/Labels.asmx/GetJarLabel",,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            processData: false,
            data: JSON.stringify(requestData),
            error: function(xhr, status, ex) {
                ...snip
            },
            success: function(r) {
                ...snip
            }
        });

enter image description here

The request seems to be submitted as far as I can tell, but the service responds 500: Invalid web service call, missing value for parameter: 'type'. I've tried switching to GET, stringifying, not stringifying but nothing works. I'm sure this worked before the migration but can't see how that would have affected it.

5
  • I'm not convinced ASMX WebMethods can accept JSON as input. They can return it, but not sure they can accept it. Try this: remove processData: false, and change data: JSON.stringify(lblData), to just data: lblData,. jQuery will then url-encoded the data parameters for you automatically. Commented Mar 14, 2019 at 14:06
  • P.S. In the code above I don't know if it's a typo but you send lblData to the server, but it's not defined. You defined requestData but that isn't used. I'm assuming it's just a mistake here, not your real code? Commented Mar 14, 2019 at 14:07
  • OTOH if you say this used to work...and it's down to something on a new server, then what changes were made between the servers? Did you ask the hosting company for a list of differences with the new server? Perhaps there's a different version of something somewhere. Although it seems quite strange that it would affect something as specific as this. Maybe your code is running on a different version of .NET or something, that's all I can think. Commented Mar 14, 2019 at 14:09
  • @ADyson The lblData/requestData was a typo, I merged two methods to post this. I originally omitted processData Commented Mar 14, 2019 at 14:14
  • " I originally omitted processData" . Ok and did you also omit the JSON.stringify() at the same time? The two things go together really. You've got such a simple structure here that you don't really particularly to send it as JSON (after all, you're hiding the complex data inside the "serialised" string) Commented Mar 14, 2019 at 14:15

2 Answers 2

1

Below you can see your ajax call. You're stringfying something called lblData. What is that? Thats not what your are declaring above. Try passing requestData instead.

$.ajax({
        type: "POST",
        url: "/Labels.asmx/GetJarLabel",,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        processData: false,
        data: JSON.stringify(lblData),
        error: function(xhr, status, ex) {
            ...snip
        },
        success: function(r) {
            ...snip
        }
    });

I'm presuming that whatever lblData is, it doesn't have a definition for type.

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

1 Comment

Sorry, that was a typo. I merged two methods to simplify the code for posting. I've corrected this.
0

I tried this on a different machine from home today (was previously at work). It seems work have some kind of weird outbound proxy setup which is interfering with requests. I guess the lesson is to try over a VPN from a different country or a phone.

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.