简体   繁体   中英

Unable to get the response from webservice

I have a requirement to verify the VAT id from below website http://ec.europa.eu/taxation_customs/vies/vatRequest.html I am hitting the webservice of above site with the bwlow code but no use

<html>
<head>
    <title></title>
    <script src="jquery-1.8.2.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            $("#BTNSERVICE").click(function (event) {
                var webserUrl = "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl";
                var soapRequest =
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" \
xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">\
    <soapenv:Header/>\
    <soapenv:Body>\
       <urn:checkVat>\
          <urn:countryCode>MS</urn:countryCode>\
          <urn:vatNumber>TESTVATNUMBER</urn:vatNumber>\
       </urn:checkVat>\
    </soapenv:Body>\
 </soapenv:Envelope>';
                $.ajax({
                    type: "POST",
                    url: webserUrl,
                    contentType: "text/xml",
                    dataType: "xml",
                    data: soapRequest,
                    success: SuccessOccur,
                    error: ErrorOccur

                });
            });
        });
        function SuccessOccur(data,status, req) {

        alert(status);
            if (status == "success")
            {

                alert('sucess');
                alert(req.responseText);
                }
        }
        function ErrorOccur(data,status, req) {
        alert(status);
            alert(req.responseText + " " + status);
        }
    </script>
</head>
<body>
    <form runat="server">
    <button id="BTNSERVICE" runat="server" text="BTNSERVICE" />
    SAMPLE Application to test service
    </form>
</body>
</html>  

After running above code it is actually supposed to throw "No,Invalid output" but it is throwing error like "undefined error".not sure what went wrong.

Note: THe SOAP request which I sent in above code was provided in below website http://ec.europa.eu/taxation_customs/vies/vatRequest.html Could anyone help me where I go wrong? Thanks in advance...

So, as I've said in my comment the problem is in the Same Origin Policy. There's no 'Access-Control-Allow-Origin' header present on the requested resource so you cannot make this call from the browser directly unless you disable CORS (but you're not going to do this in production).

What you need to do is build a lightweight service through which you can route your requests. Your service would call the SOAP VAT web service and pass back the results. You could even use the opportunity to do some logic on the server side and further simplify your client JavaScript call.

If you go with a JavaScript / NodeJs solution on the server, I suggest using a SOAP library instead of building the envelope yourself. Check out: http://www.codeproject.com/Articles/12816/JavaScript-SOAP-Client

Or if you do want to build your own in JS: http://www.ibm.com/developerworks/webservices/library/ws-wsajax/

Tried the request on SoapUI and worked so I suggest two changes:

  • Change request URL to the service URL instead of WSDL. The POST should be querying /taxation_customs/vies/services/checkVatService
  • Change the countryCode to ES because MS is not recognized.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM