Hi! This is my first time using SOAP, I have a node.js application that needs to integrate with an application that provides a SOAP api. They only have Java documentation so I am trying to figure out how to do this...
I have managed to create the client but I get an error going any further. I am trying to authenticate, I have the 3 required params and an example Java snippet. The Java snippet is:
IntimeServiceV3_0Stub.Authenticate auth=new IntimeServiceV3_0Stub.Authenticate();
auth.setAgencyRefCode("<supplied_credentials>");
auth.setUsername("<supplied_credentials>");
auth.setPassword("<supplied_credentials>");
IntimeServiceV3_0Stub.AuthenticateResponse authResp=stub.authenticate(auth);
String ticket=authResp.get_return();
System.out.println("Authentication token:" + ticket);
I am wondering how I go about converting that to using node-soap, I have at present:
client.authenticateAsync("agencyRefCode", "username", "password")
.then(res => {
console.log("SUCCESS");
console.log(res);
})
.catch(err => {
console.log("ERROR");
console.log(err);
})
I have tried a few variations of the aboe. There is also an authenticate
method available on the client for non-async requests but the same error is returned each time. Any help would be greatly appreciated!
const express = require('express')
const { soap } = require('express-soap')
const db = require('./db')
const app = express()
const port = 3000
app.use(
'/soap/transaction',
soap({
services: {
TransactionService: {
Transaction(
{
idTransaccion, idCuenta, codigoRespuesta, codigoAutorizacion, importe, importeDevolucion, moneda,
},
res
) {
db.query(
`INSERT INTO transaction (idTransaccion, idCuenta, codigoRespuesta, codigoAutorizacion, importe, importeDevolucion, moneda) VALUES (?,?,?,?,?,?,?)`,
[
idTransaccion, idCuenta, codigoRespuesta, codigoAutorizacion, importe, importeDevolucion, moneda,
],
(err, results) => {
if (err) {
console.log(err)
res({
TransactionResult:
'error for not have camps',
})
} else {
console.log(results)
if (results.insertId !== null) {
res({
TransactionResult: '00',
})
}
}
}
)
},
},
},
wsdl: `<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://www.italcred.com"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://www.italcred.com">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.italcred.com">
<s:complexType name="Transaction">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="idTransaccion" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="idCuenta" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="codigoRespuesta" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="codigoAutorizacion" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="importe" type="s:double" />
<s:element minOccurs="1" maxOccurs="1" name="importeDevolucion" type="s:double" />
<s:element minOccurs="1" maxOccurs="1" name="moneda" type="s:string" />
</s:sequence>
</s:complexType>
<s:element name="TransactionResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="TransactionResult" type="tns:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="TransactionSoapIn">
<wsdl:part name="parameters" element="tns:Transaction" />
</wsdl:message>
<wsdl:message name="TransactionSoapOut">
<wsdl:part name="parameters" element="tns:TransactionResponse" />
</wsdl:message>
<wsdl:portType name="TransactionService">
<wsdl:operation name="Transaction">
<wsdl:input name="Transaction" message="tns:TransactionSoapIn" />
<wsdl:output name="Transaction" message="tns:TransactionSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TransactionService" type="tns:TransactionService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="Transaction">
<soap:operation soapAction="http://localhost:3000/soap/transaction" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Servicio">
<wsdl:port name="TransactionService" binding="tns:TransactionService">
<soap:address location="http://localhost:3000/soap/transaction" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>`, // or xml (both options are valid)
})
)
app.listen(port, () => {
console.log(`App listening on port ${port}`)
})
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Transaction xmlns="http://localhost:3000/soap/transaction">
<idTransaccion>"123456"</idTransaccion>
<idCuenta>"1231"</idCuenta>
<codigoRespuesta>"00"</codigoRespuesta>
<codigoAutorizacion>"00"</codigoAutorizacion>
<importe>500.0</importe>
<importeDevolucion>500.0</importeDevolucion>
<moneda>"PESOS"</moneda>
</Transaction>
</soap:Body>
</soap:Envelope>
Obtain:<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://www.italcred.com" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>SOAP-ENV:Server</soap:Value>
<soap:Subcode>
<soap:Value>InternalServerError</soap:Value>
</soap:Subcode>
</soap:Code>
<soap:Reason>
<soap:Text>TypeError: Cannot read property 'outputName' of undefined</soap:Text>
</soap:Reason>
</soap:Fault>
</soap:Body>
</soap:Envelope>
Hey. Has someone experience using soap in an Angular App.
I do get a lot of errors like:
Error: ./node_modules/xml-crypto/lib/signed-xml.js
Module not found: Error: Can't resolve 'fs' in 'project-folder\node_modules\xml-crypto\lib'
Previously we used ngx-soap. But ngx-soap has no updates for angular11+
Hi,
I'm having problems with a WSDL File that has complex types that are extended from oneanthother.
in a operation it will then resolve all fields to be of the same namespace while they are actually from different namespaces.
A { a: string }, B extends A { b: number } - operation(B)
doing something like operation({ a: "1", b: "2" }) I would need the xml to be something like <A.a>1</A.a><B.b>2</B.b>. But the Result is then <B.a>1</B.a><B.b>2</B.b>
any Idea how I could best debug this within the code? Right now I'm trying to print out everything in WSD.objectToXML and just see that the nsPrefix is then always B (also for the ones that should have namespace A)
input: {
VUNr: 'VUNr|xsd:string|minLength,maxLength',
ClientId: 'xsd:string',
'TechnischeParameter[]': {
Key: 'xsd:string',
Value: 'xsd:string',
targetNSAlias: '__tns__',
targetNamespace: 'urn:CommonServiceTypes-1-1-0'
},
Hi, I'm trying to use v0.43, but it ships with a very old version of Axios 0.21, because of this it fails typescript checks when I pass it an AxiosInstance 0.26 using options.request. A couple of thoughts, I can work around it by making axios: any, not optimal.
Is there a way to not bundle axios but refer to a dependency? Or alternatively, could you just upgrade to a newer release? I believe 0.21 has security issues. https://snyk.io/vuln/npm:axios@0.21.1
Error occurred in handler for 'MSSANTE_LIST_EMAILS': TypeError: Cannot read property 'description' of undefined
at SAXParser.p.onopentag (/Users/myUser/Saturn/dist/webpack:/node_modules/soap/lib/wsdl/index.js:238:1)
at emit (/Users/myUser/Saturn/dist/webpack:/node_modules/sax/lib/sax.js:624:1)
at emitNode (/Users/myUser/Saturn/dist/webpack:/node_modules/sax/lib/sax.js:629:1)
at openTag (/Users/myUser/Saturn/dist/webpack:/node_modules/sax/lib/sax.js:825:1)
at SAXParser.write (/Users/myUser/Saturn/dist/webpack:/node_modules/sax/lib/sax.js:1391:1)
at WSDL../node_modules/soap/lib/wsdl/index.js.WSDL.xmlToObject (/Users/myUser/Saturn/dist/webpack:/node_modules/soap/lib/wsdl/index.js:443:1)
at parseSync (/Users/myUser/Saturn/dist/webpack:/node_modules/soap/lib/client.js:289:1)
at /Users/myUser/Saturn/dist/webpack:/node_modules/soap/lib/client.js:496:1
at /Users/myUser/Saturn/dist/webpack:/node_modules/soap/lib/http.js:199:1
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
I am trying to use WSSecurityCert. And I am using additionalReferences :['was:To'] to sign the tag but I am getting
Error: the following xpath cannot be signed because it was not found: //*[name(.)='wsa:To']
and also
TypeError: Cannot read property 'setSecurity' of undefined
exports.findAll = (req, res, next) => {
let server = req.body.server;
let agencyCode = req.body.agencyCode;
let branchCode = req.body.branchCode;
let transactionCode = req.body.transactionCode;
let userId = req.body.userId;
let ic = req.body.input_ic;
var date = new Date(); // Or the date you'd like converted.
var reqDate = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString();
reqDate = reqDate.substring(0, reqDate.length - 5);
const soapRequest = require('easy-soap-request');
const fs = require('fs');
const xml2js = require('xml2js');
const url = `${server}`;
const header = {
'user-agent': 'SSIPR',
'Content-Type': 'text/xml;charset=UTF-8',
};
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:crs="http://tempuri.org/CRSService">
<soapenv:Header/>
<soapenv:Body>
<crs:retrieveCitizensDataReq>
<AgencyCode>${agencyCode}</AgencyCode>
<BranchCode>${branchCode}</BranchCode>
<UserId>${userId}</UserId>
<TransactionCode>${transactionCode}</TransactionCode>
<RequestDateTime>${reqDate}</RequestDateTime>
<ICNumber>${ic}</ICNumber>
<RequestIndicator>A</RequestIndicator>
</crs:retrieveCitizensDataReq>
</soapenv:Body>
</soapenv:Envelope>`;
// usage of module
(async () => {
try{
const { response } = await soapRequest({ url: url, headers: header, xml: xml, timeout: 30000 }); // Optional timeout parameter(milliseconds)
const { headers, body, statusCode } = response;
xml2js.parseString(body.toString(),
{ tagNameProcessors: [ xml2js.processors.stripPrefix ]},
function (err, result) {
res.status(200).json(result);
})
}catch(err){
next(err);
}
})();
}