简体   繁体   English

无法从Web服务获取响应

[英]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 我需要从下面的网站http://ec.europa.eu/taxation_customs/vies/vatRequest.html验证增值税ID,但我使用bwlow代码访问了上述网站的网络服务,但没有用

<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. 运行上述代码后,实际上应该抛出“ No,Invalid output”,但它会抛出“ undefined error”之类的错误。不确定出了什么问题。

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? 注意:我在上面的代码中发送的SOAP请求是在以下网站http://ec.europa.eu/taxation_customs/vies/vatRequest.html中提供的,谁能帮助我解决我的问题? 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). 所请求的资源上不存在“ Access-Control-Allow-Origin”标头,因此除非禁用CORS,否则您无法直接从浏览器进行此调用(但您不会在生产中进行此操作)。

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. 您的服务将调用SOAP VAT Web服务并传回结果。 You could even use the opportunity to do some logic on the server side and further simplify your client JavaScript call. 您甚至可以借此机会在服务器端执行一些逻辑,并进一步简化客户端JavaScript调用。

If you go with a JavaScript / NodeJs solution on the server, I suggest using a SOAP library instead of building the envelope yourself. 如果您在服务器上使用JavaScript / NodeJs解决方案,则建议您使用SOAP库而不是自己构建信封。 Check out: http://www.codeproject.com/Articles/12816/JavaScript-SOAP-Client 检出: 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/ 或者,如果您确实想在JS中构建自己的网站,请访问http : //www.ibm.com/developerworks/webservices/library/ws-wsajax/

Tried the request on SoapUI and worked so I suggest two changes: 在SoapUI上尝试了该请求并开始工作,因此我建议进行两项更改:

  • Change request URL to the service URL instead of WSDL. 将请求URL更改为服务URL,而不是WSDL。 The POST should be querying /taxation_customs/vies/services/checkVatService POST应查询/ taxation_customs / vies / services / checkVatService
  • Change the countryCode to ES because MS is not recognized. 因为无法识别MS,所以将countryCode更改为ES。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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