如何解决通过服务层以角度方式处理SOAP响应
我创建了一个表单,并调用了服务层。如果必须处理基本的REST,我肯定会通过订阅来编写以下代码:
onSubmit(): void {
this.submitted = true;
const response = this.documentCreateForm.value;
this.apiService.postDocument(response).subscribe( returnValue => {
console.log('return value: ',returnValue );
// other stuffs here ...
});
}
我的问题是我必须在SOAP请求中发送JSON(不是我的选择):
postDocument(response: any): void {
console.log('Response form in service layer: ',response);
const xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST',this.baseUrl + '/uploadDocument.wsdl',true);
// build SOAP request
const soapRequest =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ' +
'xmlns:bran="http://www.bottomline.com/soap/branch/">' +
'<soapenv:Header/>' +
'<soapenv:Body>' +
'<bran:CallBranch soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' +
'<JSONRequest xsi:type="xsd:string">' +
JSON.stringify(response) +
'</JSONRequest>' +
'</bran:CallBranch>' +
'</soapenv:Body>' +
'</soapenv:Envelope>';
console.log('SOAP REQUEST ');
console.log(soapRequest.toString());
xmlhttp.onreadystatechange = () => {
if (xmlhttp.readyState === 4) {
if (xmlhttp.status === 200) {
alert(xmlhttp.responseText);
console.log('Response : ');
console.log(xmlhttp.responseText);
}
}
};
// Send the POST request
xmlhttp.setRequestHeader('Content-Type','text/xml');
xmlhttp.send(soapRequest);
}
我真的不知道如何在组件的onSubmit()方法中检索从远程服务器收到的响应。似乎我没有观察到。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。