2017-04-26 23 views
7

Tôi đang cố gắng đăng dữ liệu lên api xà phòng nhưng không thể làm như vậy. tôi đã thử tất cả các phương pháp có thể nhưng tôi vẫn gặp lỗi khi gọi api.Đăng dữ liệu lên apAP SOAP với js góc

api của tôi là - http://xyz.asmx?op=UserRegistration

và nó excepts dữ liệu ở định dạng xml như

<?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> 
    <UserRegistration xmlns="http://Service/"> 
     <Usercreditional>string</Usercreditional> 
    </UserRegistration> 
    </soap:Body> 
</soap:Envelope> 

Những điều tôi đã cố gắng -

1> Với $ http.post

var soapData = '<?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>'+ 
    '<UserRegistration xmlns="http://Service/">'+ 
    '<Usercreditional>[{ \'DeviceUUID\': \'' + data.DeviceUUID + '\', ' +   
         "\"DevicePushID\":\"" + data.DevicePushID + "\"}]" + 
        '</Usercreditional></UserRegistration></soap:Body></soap:Envelope>'; 

return $http({ 
      method: 'POST', 
      url: ' http://xyz.asmx?op=UserRegistration', 
      data : soapData, 
      headers : { "Content-Type" : 'application/xml'} 
     }); 

điều này cho lỗi "không thể xử lý yêu cầu. --- > yếu tố gốc là mất tích"

2> Với SoapClient

var deferred = $q.defer(); 
var soapParams = new SOAPClientParameters(); 
var userCredentials = [{"DeviceUUID": data.DeviceUUID, "DevicePushID": data.DevicePushID}]; 
for (var param in userCredentials) 
    { 
     soapParams.add(param, soapParams[param]); 
    } 
var soapCallback = function (e) { 
    if (e.constructor.toString().indexOf("function Error()") != -1) { 
     deferred.reject(e); 
     } else { 
     deferred.resolve(e); 
      } 
     };  SOAPClient.invoke(' http://xyz.asmx', 'UserRegistration', soapParams, true, soapCallback); 
     return deferred.promise; 

này được đưa ra lỗi không thể đọc thuộc tính 'getElementsByTagName' null

có thể bất cứ ai hãy giúp tôi trong vụ việc này? Cố gắng hầu như tất cả mọi thứ vẫn không có may mắn. cảm ơn trước

Trả lời

5
  1. Với $ http.post

Bạn có thể sử dụng dịch vụ $ http để gửi dữ liệu đến các API SOAP như sau:

enter image description here

var headers = { 
       'Content-Type': 'text/xml; charset=utf-8' 
      }; 
return $http({ 
       method: 'POST', 
       url: 'http://providerservice.fmcnetwork.net/MobileAppService.asmx?op=UserRegistration', 
       data : soapData, 
       headers : headers 
      }); 
  1. Với angular-soap

Bạn cũng có thể sử dụng plugin angular-soap được xây dựng trên đầu ứng dụng SOAP và sử dụng $ soap dịch vụ để đạt được như vậy.

Ví dụ:

angular.module('myApp', ['angularSoap']) 

.factory("testService", ['$soap',function($soap){ 
    var base_url = "http://www.cooldomain.com/SoapTest/webservicedemo.asmx"; 

    return { 
     CreateUser: function(firstName, lastName){ 
      return $soap.post(base_url,"CreateUser", {firstName: firstName, lastName: lastName}); 
     } 
    } 
}]) 

.controller('MainCtrl', function($scope, testService) { 

    testService.CreateUser($scope.firstName, $scope.lastName).then(function(response){ 
    $scope.response = response; 
    }); 

}) 
2

Hãy thử điều này :)

var soapData = '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">'+ 
    '<Body>'+ 
    '<UserRegistration xmlns="http://FmcMobileApplicationService/">'+ 
    '<Usercreditional>{ \'DeviceUUID\': \'' + data.DeviceUUID + '\', ' +   
         "\"DevicePushID\":\"" + data.DevicePushID + "\"}" + 
        '</Usercreditional></UserRegistration></Body></Envelope>'; 

return $http({ 
      method: 'POST', 
      url: 'http://providerservice.fmcnetwork.net/MobileAppService.asmx' 
      data : soapData, 
      headers : { "Content-Type" : 'application/xml'} 
     }); 

thay đổi từ mã của bạn

  • Không gửi header xml
  • xà phòng đã thay đổi: Envelope để Phong bì
  • Đã diễn ra các không gian tên schema
  • đổi tên xà phòng: Body để cơ thể
  • Posted to MobileAppService.asmx mà không querystring
  • Sent một đối tượng { "DeviceUUID": "1", "DevicePushID": "2"} không một mảng

Tôi nhận được phản hồi.Đó là một sản phẩm nào một lần nhưng một thực tế :) Tôi đã sử dụng 1 và 2 là DeviceUUID và DevicePushID tương ứng. Do đó một phản ứng trống rỗng tôi giả định.

Trả lời:

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
     <UserRegistrationResponse xmlns="http://FmcMobileApplicationService/"> 
      <UserRegistrationResult>[]</UserRegistrationResult> 
     </UserRegistrationResponse> 
    </soap:Body> 
</soap:Envelope> 
Các vấn đề liên quan