0

I tried a web service + ajax call as written by Fuxiang. I created the aspx page and the service (.asmx) and hosted it in the server in IIS. The code works perfectly when i run it in the local server.

When I call the same from a remote machine i get internal 500 error. Why is this so? The same happens when i try with angular instead of jquery ajax. What is the work around?

ERROR

Failed to load resource: the server responded with a status of 500 (Internal Server Error) Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'.

Here's the code:

aspx

 <script>
        //no paras to call
        $(document).ready(function () {

            $.ajax({
                type: "POST",
                contentType: "application/text",
                url: "Test_WebService.asmx/HelloWorld",
                data: {},
                dataType: 'text',
                error: function (err) {
                    $('#content').html(err);
                },
                success: function (result) {
                    $('#content').html(result);
                    //  alert(result);
                }
            });

            $('#loading').ajaxStart(function () {
                $(this).show();
            }).ajaxStop(function () {
                $(this).hide();
            });
        });

    </script>


<body>
    <form id="form1" runat="server">
        <div id="content">
        </div>
        <div id="loading">
            service is handling,please wait......
        </div>
    </form>
</body>

asmx

 [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class Test_WebService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            System.Threading.Thread.Sleep(2000);
            return "Hello World";
        }
    }

Update:

I have added the following in web config and it hasn't made a change:

 <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>

I have registered the asp version in the web server, still it does not work

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regii‌​s -i
Linda
  • 147
  • 2
  • 20
  • You cant ajax call that normally dear. to shorten the issue use this : https://github.com/doedje/jquery.soap/blob/master/README.md – Masoud Andalibi Sep 05 '17 at 11:16
  • 1
    Read [ask] and research that error message. Plenty of suggestions to fix it apart from that first one. You may also want to reconsider using ASMX, it's deprecated. Try WebAPI or WCF. – CodeCaster Sep 05 '17 at 11:19
  • Hi CodeCaster! I have already used that link and tried all the solutions provided. Nothing worked. Moreover my context is different. My code works perfectly in the local machine. I am able to open the asmx in the remote machine. Once i club it with the angular js/ jquery ajax call this issue occurs. Wish you know a solution! – Linda Sep 05 '17 at 11:42
  • @Linda, please have a look at https://stackoverflow.com/questions/879362/calling-asmx-from-jquery – Anton Norko Sep 05 '17 at 11:46
  • Your WebMethod doesn't accept any parameters and you are still trying to post empty object. Try GET method or change signature of HelloWorld method. – Pankaj Kapare Sep 05 '17 at 11:47

0 Answers0