通过服务层以角度方式处理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 (将#修改为@)