I am creating an endpoint that will make a request to a SOAP service with soap npm
library. This is the imlementation I’m using.
<code>import xml2js from "xml2js";
const soap = require('soap');
const wsdlPath = 'path_to_wsdl.wsdl';
const endPoint = endpoint_to_service;
const clientOptions = {
disableCache: false,
endpoint: endPoint,
escapeXML: false,
preserveWhitespace: true,
};
let soapClient = await soap.createClientAsync(wsdlPath, clientOptions);
//privateKey and cert are the variables containing my certificates for the service
soapClient.setSecurity(new soap.WSSecurityCert(privateKey, cert));
soapClient.addHttpHeader('Content-Type', 'application/soap+xml');
const builder = new xml2js.Builder({
headless: true,
rootName: "servicerequest",
});
//variable request being an object with the parameters for the service
const xml = builder.buildObject(request);
const result = (await soapClient.methodAsync({
_xml: xml,
}));
</code>
<code>import xml2js from "xml2js";
const soap = require('soap');
const wsdlPath = 'path_to_wsdl.wsdl';
const endPoint = endpoint_to_service;
const clientOptions = {
disableCache: false,
endpoint: endPoint,
escapeXML: false,
preserveWhitespace: true,
};
let soapClient = await soap.createClientAsync(wsdlPath, clientOptions);
//privateKey and cert are the variables containing my certificates for the service
soapClient.setSecurity(new soap.WSSecurityCert(privateKey, cert));
soapClient.addHttpHeader('Content-Type', 'application/soap+xml');
const builder = new xml2js.Builder({
headless: true,
rootName: "servicerequest",
});
//variable request being an object with the parameters for the service
const xml = builder.buildObject(request);
const result = (await soapClient.methodAsync({
_xml: xml,
}));
</code>
import xml2js from "xml2js";
const soap = require('soap');
const wsdlPath = 'path_to_wsdl.wsdl';
const endPoint = endpoint_to_service;
const clientOptions = {
disableCache: false,
endpoint: endPoint,
escapeXML: false,
preserveWhitespace: true,
};
let soapClient = await soap.createClientAsync(wsdlPath, clientOptions);
//privateKey and cert are the variables containing my certificates for the service
soapClient.setSecurity(new soap.WSSecurityCert(privateKey, cert));
soapClient.addHttpHeader('Content-Type', 'application/soap+xml');
const builder = new xml2js.Builder({
headless: true,
rootName: "servicerequest",
});
//variable request being an object with the parameters for the service
const xml = builder.buildObject(request);
const result = (await soapClient.methodAsync({
_xml: xml,
}));
The problem is when the code is executed, I get the following error
<code>ERROR Invoke Error
{
"errorType": "TypeError",
"errorMessage": "Converting circular structure to JSONn --> starting at object with constructor 'ClientRequest'n | property 'socket' -> object with constructor 'TLSSocket'n --- property '_httpMessage' closes the circle",
"stack": [
"TypeError: Converting circular structure to JSON",
" --> starting at object with constructor 'ClientRequest'",
" | property 'socket' -> object with constructor 'TLSSocket'",
" --- property '_httpMessage' closes the circle",
" at JSON.stringify (<anonymous>)",
" at t.savePaymentHandler (/var/task/src/v1/functions/savePayment/index.js:8:706225)",
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
" at async /var/task/src/v1/functions/savePayment/index.js:8:923167"
]
}
</code>
<code>ERROR Invoke Error
{
"errorType": "TypeError",
"errorMessage": "Converting circular structure to JSONn --> starting at object with constructor 'ClientRequest'n | property 'socket' -> object with constructor 'TLSSocket'n --- property '_httpMessage' closes the circle",
"stack": [
"TypeError: Converting circular structure to JSON",
" --> starting at object with constructor 'ClientRequest'",
" | property 'socket' -> object with constructor 'TLSSocket'",
" --- property '_httpMessage' closes the circle",
" at JSON.stringify (<anonymous>)",
" at t.savePaymentHandler (/var/task/src/v1/functions/savePayment/index.js:8:706225)",
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
" at async /var/task/src/v1/functions/savePayment/index.js:8:923167"
]
}
</code>
ERROR Invoke Error
{
"errorType": "TypeError",
"errorMessage": "Converting circular structure to JSONn --> starting at object with constructor 'ClientRequest'n | property 'socket' -> object with constructor 'TLSSocket'n --- property '_httpMessage' closes the circle",
"stack": [
"TypeError: Converting circular structure to JSON",
" --> starting at object with constructor 'ClientRequest'",
" | property 'socket' -> object with constructor 'TLSSocket'",
" --- property '_httpMessage' closes the circle",
" at JSON.stringify (<anonymous>)",
" at t.savePaymentHandler (/var/task/src/v1/functions/savePayment/index.js:8:706225)",
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
" at async /var/task/src/v1/functions/savePayment/index.js:8:923167"
]
}
I’m not sure where or why this error is coming up. I would appreciate for any insights on this issue
1