0

I need to call a web service and pass it xml and authentication data. Here is what i came up with so far:

var xml ="<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>"
+ "<soapenv:Header/>"
+ "<soapenv:Body>"
    + "..."
    + "</soapenv:Body></soapenv:Envelope>";


var config = {
            method: "POST",
            url: 'http://....wsdl',
            data: xml
        };
        $http(config).
            then(function (data, status, xhr) {
                $scope.MyID = data;
            }, function errorCallback(xhr) {
                //print error to console.
                console.log(xhr.responseText);
            });

I need to figure out how can I pass in username and password. And also the above gives me an error:

XMLHttpRequest cannot load http://....wsdl. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:' is therefore not allowed access.

The strange part is that when I called the service from .NET the same way, there was no issue with access-control-allow-origin

Coding Duchess
  • 6,445
  • 20
  • 113
  • 209

1 Answers1

0

Since you are using angular for http requery use any of the following code to pass authentication.

app.run(['$http', function($http) {
    $http.defaults.headers.common['Authorization'] = /* ... */;
}]);

app.config(['$httpProvider', function($httpProvider) {
    $httpProvider.defaults.headers.common['Authorization'] = /* ... */;
}])

Try this Library hope it helps

https://github.com/andrewmcgivery/angular-soap

Saajan
  • 670
  • 1
  • 9
  • 20
  • but what do I pass to the header? token? – Coding Duchess Nov 15 '16 at 16:27
  • http://codereview.stackexchange.com/a/103751 ... check this link for detailed explanation on how to pass authentication to header. – Saajan Nov 16 '16 at 16:11
  • how would I generate access token in angular given username and password? – Coding Duchess Nov 16 '16 at 19:20
  • Found it here: http://jasonwatmore.com/post/2014/05/26/angularjs-basic-http-authentication-example – Coding Duchess Nov 16 '16 at 19:31
  • http://stackoverflow.com/a/125062/3094001 ... i too suggest u to drop soap webservice . since it is very complicated to do in javascript part. – Saajan Nov 16 '16 at 21:29
  • Im really sorry that i couldnt help you with a proper solution. Since SOAP with javascript is very complicated since SOAP reinvents a lot of the HTTP wheel in its quest for protocol-independence and it is slow. if you still want to continue with SOAP . try this library hope it helps https://github.com/andrewmcgivery/angular-soap – Saajan Nov 16 '16 at 21:37