0

I have a c# asmx web service code like below.

[WebMethod]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public void getPolicyDetails(string CustId, string PolicyType)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();
        Context.Response.Clear();
        Context.Response.ContentType = "application/json";
        clsPolicy data = new clsPolicy();
        try
        {
            string policyTxt = "";
            //get PolicyTxt from Database
            data.Message = policyTxt.ToString();
        }
        catch (Exception ex)
        {
        }
        Context.Response.Write(js.Serialize(data));
    }

Now, I am trying to consume this web service in asp.net. This web-service is already being used in my android project successfully.

When I try to use call it via javascript, it gives me a 500 - Internal server error. Below is my Javascript code.

 function getPolicy(policyType) {
            $.ajax({
                type: "POST",
                url: "http://myurl/productsearch.asmx/getPolicyDetails",
                data: '{CustId: 106206,PolicyType: "' + policyType + '" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                    alert(response.d);
                }
            });
        }
        function OnSuccess(response) {
            alert(response.d);
        }

What could be the problem?

2 Answers 2

1

Error 500 Internal Server Error is related to the error in the webservice.

Different Methods to debug/log the error

  1. In catch block log that error into the text file using file handling code.

  2. Debug your webservice by attaching it to the w3wp process if you have access to the server where service is deployed and visual studio is installed on that server.

  3. You can check the error windows event viewer

    Control Panel -> Administrative tools -> Event Viewer

    On left side panel expand Windows Logs and Click on application menu and find the details in the error logs related to your application

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

Comments

0
public void getPolicyDetails(string CustId, string PolicyType)

You define CustID as string but in your json it is integer

data: '{CustId: 106206,PolicyType: "' + policyType + '" }'

Also start using JSON.stringify for create of your data.

var policyType = 'something';
var custID = '106206';
data: JSON.stringify({CustId:custID, PolicyType: policyType })

4 Comments

Ok. Let me try with a string and reply to you.
Modified the code: var custid = "106206"; data: '{CustId: "' + custid + '",PolicyType: "' + policyType + '" }'.
@milanm write is using JSON.stringify like I worte it
Unfortunately, it is still not working. There is another webservice on the same page where I am not passing parameters and that is working absolutely fine. I am wondering what is the issue in this one?

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.