Wednesday, 28 August 2019

Calling WebService Using AJAX jQuery With SOAP

I'm copy/pasting this HTML code from this guide but I cannot make the service work.
The article talks about a WebService used to do simple arithmetic calculation, and I was lucky enought to find an endpoint that provides the same service:
http://www.dneonline.com/calculator.asmx?WSDL
So I fire up WcfStorm and if I try to request a SOAP call that makes 3 + 5 I receive as result 8:
enter image description here
All good, so now let's inject the call:
<Add>
  <MethodParameters>
    <intA>3</intA>
    <intB>5</intB>
  </MethodParameters>
</Add>

Into the HTML code that I find in the article:
<html>
<head>
    <title></title>
    <script src="Scripts/jquery-1.8.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#BTNSERVICE").click(function (event) {
                var webserUrl = "http://www.dneonline.com/calculator.asmx?WSDL";
                var soapRequest =
'<?xml version="1.0" encoding="utf-8"?> \
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<Add> \
  <MethodParameters> \
    <intA>0</intA> \
    <intB>0</intB> \
  </MethodParameters> \
</Add> \
</soap:Body> \
</soap:Envelope>';
                $.ajax({
                    type: "POST",
                    url: webserUrl,
                    contentType: "text/xml",
                    dataType: "xml",
                    data: soapRequest,
                    success: SuccessOccur,
                    error: ErrorOccur
                });
            });
        });
        function SuccessOccur(data, status, req) {
            if (status == "success")
                alert(req.responseText);
        }
        function ErrorOccur(data, status, req) {
            alert(req.responseText + " " + status);
        }
    </script>
</head>
<body>
    <form runat="server">
    <asp:button id="BTNSERVICE" runat="server" text="BTNSERVICE" />
    SAMPLE Application to test service
    </form>
</body>
</html>  

I save he file as an .HTML file and I open if with FireFox but no joy:
enter image description here
What am I doing wrong? I'm literally following the guide step by step.


from Calling WebService Using AJAX jQuery With SOAP

No comments:

Post a Comment