Я пытаюсь использовать SOAP-сервер в angular 4 с пакетом ngx-soap.
Однако я получаю сообщение об ошибке перекрестного источника (нет доступа на стороне сервера, но нет проблем, и Access-Control-Allow-Origin исправен), а код состояния http - 400.
Я действительно не знаю, почему я получил эту ошибку. Пожалуйста, помогите мне.
Итак, это мой код (из пакета ngx-soap).
Он создал клиент SOAP, вызывает сервер SOAP (http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso) и использует почтовый запрос для восстановления имени страны из операции CountryName.
export class AppComponent implements OnInit{
jsonResponse: any;
xmlResponse: string;
message: string;
loading: boolean;
sCountryISOCode: string;
private client: Client;
constructor(
private http: HttpClient,
private soap: SOAPService
) { }
ngOnInit() {
this.http.get('/assets/tt.wsdl',
{responseType: 'text'}).subscribe(response => {
console.log(response);
if (response) {
this.client = this.soap.createClient(response);
}
});
}
soapCall() {
this.clear();
this.loading = true;
const body = {
sCountryISOCode: this.sCountryISOCode
};
this.client.operation('CountryName', body)
.then(operation => {
console.log(operation);
if (operation.error) {
console.log('Operation error', operation.error);
return;
}
console.log(operation.url);
console.log(operation.xml);
console.log(operation.headers);
this.http.post(operation.url, operation.xml,
{ headers: operation.headers, responseType: 'text', withCredentials: true }).subscribe(
response => {
console.log('GG');
this.xmlResponse = response;
this.jsonResponse = this.client.parseResponseBody(response);
try {
this.message = this.jsonResponse.Body.AddResponse.AddResult;
} catch (error) { }
this.loading = false;
},
err => {
console.log('Error calling ws', err);
this.loading = false;
console.log();
}
);
})
.catch(err => console.log('Error', err));
}
clear() {
this.message = undefined;
this.jsonResponse = undefined;
this.xmlResponse = undefined;
}
}
export interface Output {
AddResult?: string;
}