I'm trying to get a really simple call to a SOAP web service to work using Angular2 and Http POST. if I post the same message using POSTMAN it works fine just by setting the content type to text/xml.
With Angular2 I'm getting these errors:-
SEC7120: Origin http://localhost:3004 not found in Access-Control-Allow-Origin header
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied
any help would be appreciated.
this is the service code
import { Injectable } from 'angular2/core';
import { Http, Request, Response, Headers, RequestMethod, RequestOptions } from 'angular2/http';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class PaymentsService {
private body: string = `<?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>
<HelloWorld xmlns="http://bernera.zapto.org/" />
</soap:Body>
</soap:Envelope>`;
private result;
constructor(private http: Http) { }
callSOAP() {
var headers = new Headers();
headers.append('Content-Type', 'text/xml');
headers.append('Access-Control-Request-Method', 'POST');
headers.append('Access-Control-Request-Headers', 'X-Custom-Header');
headers.append('Access-Control-Allow-Origin', 'http://localhost:3004');
this.http.post('http://bernera.zapto.org/astronomy/astronomy.asmx',
this.body,
{ headers: headers })
.subscribe(
data => this.result = data,
err => this.logError(err),
() => console.log('Call complete')
);
alert('result ' + this.result);
}
logError(err) {
console.error('There was an error: ' + err.statusText);
alert('There was an error: ' + err.statusText);
}
}