2016-06-22 4 views
0

angularjsのsoap apiに投稿データを送信する際に問題が発生しました。投稿データをxml文字列として構築し、適切なヘッダーを設定しましたが、ポストリクエストがインスタンス化されるたびにhttpエラーコールバックを取得します以下は私のコードです角度のjsのSOAP API

var mydata = "<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:Body><Query xmlns="http://myurl.com/"><Policy_Debit_NoteNo>123Asewe</Policy_Debit_NoteNo></Query></soap12:Body></soap12:Envelope>" 

var header = { 
       "content-type":"application/soap+xml", 
       "Accept": "application/soap+xml" 
      }; 

$http.post("http://myurl.com/mservice/service.asmx",mydata,header) 
    .then(function(res){ 
      //success 
      alert("success: " + JSON.stringify(res)); 
      }, 
      function(err) { 
      //error 
      alert("error: " + JSON.stringify(err)); 
     }); 
+0

、エラーメッセージは何ですか? – klappvisor

+0

"メディアの種類がサポートされていないため、サーバーは要求を処理できません" – TobiSkillZ

+0

質問にエラーメッセージを追加して完全なものにする方が良いでしょう。あなたのサーバーがヘッダーに異なるContent-Typeを期待しているようです。 – klappvisor

答えて

0

最初の疑わしいのはヘッダーです。 docsによると、あなたのURLが.asmxを含んでいるので、それは

var header = { 
      "Content-Type":"application/soap+xml", 
      "Accept": "application/soap+xml" 
     }; 
var config = { 
    headers: header 
}; 

$http.post("http://myurl.com/mservice/service.asmx", mydata, config) 
    .then(function(res){ 
     //success 
     alert("success: " + JSON.stringify(res)); 
     }, 
     function(err) { 
     //error 
     alert("error: " + JSON.stringify(err)); 
    }); 

する必要があり、ASP.NETサーバーで、そのサーバーのデフォルトのContent-Typeをチェックし、それがapplication/soap+xmlをサポートしていないこと、そうapplication/xmlあるいはtext/xmlをしようとします。

それは次のように使用しようと解決しない場合:

$http({ 
    method: 'POST', 
    url: 'http://myurl.com/mservice/service.asmx', 
    datatype: 'xml', 
    data: mydata 
    contentType: "application/xml; charset=utf-8" 
}).success(function(data,status, headers, config){ 
    if(status == '200'){ 
    alert(data.d); 
    } 
}).error(function(data,status, headers, config){alert("error: " + status});  
+0

はまだ同じエラーメッセージを受け取っています – TobiSkillZ

+0

@TobiSkillZ 'application/xml'と' text/xml'で試してみましたか?あなたは、SOAPAction:http:// myurl.com/mservice/service.asmx/PostMyData'のようなSOAPリクエストのための別のヘッダが必要です。 – klappvisor

+0

私は持っていますアプリケーション/ xmlとtext/xmlの両方で試しました...私もSOAPActionをヘッダーに追加しましたが、何も返されませんでした。 – TobiSkillZ