2017-07-25 212 views
0

調用soap服務會拋出404錯誤,但在SOAP UI中正常工作。某處我發現這可能是由於CORS問題,所以我設置標題爲「訪問控制允許來源」:「*」,但沒有運氣SOAP服務通過AJAX調用失敗,但在SOAPUI中正常工作

下面是我如何調用服務

let _this=this; 
    var webServiceURL = 'http://localhost:8082/ode/processes/WS_Invocation.WS_InvocationPort'; 


var soapMessage = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.invocation.tps"><soapenv:Header/><soapenv:Body><ws:WS_InvocationRequest><ws:input>1</ws:input><ws:input1>Mohan</ws:input1></ws:WS_InvocationRequest></soapenv:Body></soapenv:Envelope>' 

    $.ajax({ 
     url: _this.webServiceURL, 
     type: "POST", 
     dataType: "xml", 
     crossDomain: true, 
     headers: { 
       'Access-Control-Allow-Origin': '*' 
      }, 
     data: _this.soapMessage, 
     contentType: "text/xml; charset=\"utf-8\"", 
     success: _this.OnSuccess, 
     error: _this.OnError 
    }); 

下面是SOAP UI成功響應 enter image description here

+0

從您的$ .ajax調用中刪除'headers:{'Access-Control-Allow-Origin':'*'}''。 Access-Control-Allow-Origin是服務器必須發送的*響應*標頭。將它作爲請求標題發送不會爲您解決任何問題。刪除之後,要獲得更多幫助,請使用https://stackoverflow.com/posts/45309437/edit來編輯/更新您的問題,並在瀏覽器devtools控制檯中添加您看到的確切錯誤消息。 – sideshowbarker

回答

0

這是CORS問題,您應該啓用CORS所有在你的API服務,每個平臺都有不同的配置中一樣的NodeJS,阿帕奇,Nginx的或等

,你可以看看d ocumentation如何,你可以只是做了要求在這裏https://enable-cors.org/index.html

網絡業務啓動CORS這樣

//jQuery <= 1.12.x 
 
$.get(API_URL) 
 
.success(function(response) { 
 
    var res = $(response).find('YOUR_NODE'); 
 
}) 
 
.error(function(err) { 
 

 
}); 
 

 
//jQuery > 1.12.x 
 
$.get(API_URL) 
 
.then(function(response) { 
 
    var res = $(response).find('YOUR_NODE'); 
 
}) 
 
.catch(function(err) { 
 

 
});

關心的東西。

+0

我已經通過設置標題'Access-Control-Allow-Origin'啓用了CORS:'*'。這是不夠的?另外我從瀏覽器控制檯看到responseText顯示**「無法POST」**。 – Mohan

+0

@Mohan它意味着你的路由器設置沒有設置爲POST?你在用什麼? ASP.NET? –

相關問題