๐ง [Support] SOAP and NodeJS
gajet5 opened this issue ยท 5 comments
๐ง Support Request
Has anyone tried to implement this?
My test code.
const soap = require('soap');
const url = 'http://localhost:7878/';
(async () => {
soap.createClient(
url,
{
wsdl_options: { method: 'POST' },
overrideRootElement: {
namespace: 'urn:MaNGOS'
}
},
(err, client) => {
if (err) {
console.log(err);
return;
}
client.executeCommand({ command: 'server info' }, (err, result) => {
if (err) {
console.log(err);
return;
}
console.log(result);
});
}
);
})();
In the console, I get this:
"C:\Program Files\nodejs\node.exe" D:\git\s-evil.ru\src\app\lib\soap.js
Error: Invalid WSDL URL: http://localhost:7878/
Code: 500
Response Body: <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:ns1="urn:MaNGOS"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Client</faultcode><faultstring>Data required for operation</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
at D:\git\s-evil.ru\node_modules\soap\lib\wsdl\index.js:1292:26
at handleBody (D:\git\s-evil.ru\node_modules\soap\lib\http.js:178:17)
at D:\git\s-evil.ru\node_modules\soap\lib\http.js:210:24
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Process finished with exit code 0
Some data is required for the operation. I don't understand which ones.
Config:
SOAP.Enabled = 1
SOAP.IP = 127.0.0.1
SOAP.Port = 7878
Are you sure the WSDL URL is correct? Typically it'll end with .wsdl.
Have you tried navigating to your stipulated URL in your browser, to see if you get a valid WSDL response?
https://github.com/vmangos/core/blob/development/contrib/soap/example.php
I looked at this example and in the documentation, there are examples without this addition in the line.
Many of the examples continue to include ?WSDL
in the URL. And in my experience, that piece is (often) required. Again, I ask: have you tried navigating to the URL in your code and seeing if you get a valid WSDL response? I wager you're not.
I think soap.createClient()
doesn't work for non-WSDL RPC services, but you can use Axios instead:
const axios = require('axios')
const username = 'ADMINISTRATOR'
const password = 'ADMINISTRATOR'
const host = 'http://127.0.0.1:7878'
const command = 'server info'
const buildSoapRequest = command => `
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:MaNGOS">
<SOAP-ENV:Body>
<ns1:executeCommand>
<command>${command}</command>
</ns1:executeCommand>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
`
const soapRequest = buildSoapRequest(command)
;(async () => {
try {
const response = await axios.post(
host,
soapRequest,
{
headers: {
'Content-Type': 'text/xml',
'SOAPAction': 'urn:MaNGOS'
},
auth: {
username: username,
password: password
}
}
)
console.log('Command succeeded! Output:', response.data)
} catch (error) {
console.error('Command failed! Reason:', error.message)
}
})()
This works for me and gives me the following output:
Command succeeded! Output: <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:ns1="urn:MaNGOS"><SOAP-ENV:Body><ns1:executeCommandResponse><result>Core revision: 9e63169e579bc29174ec / 2024-09-26 18:43:08 +0300 / Linux_x64 (little-endian)
Players online: 0 (0 queued). Max online: 0 (0 queued).
Server uptime: 11 Minutes 15 Seconds.
</result></ns1:executeCommandResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Many of the examples continue to include
?WSDL
in the URL. And in my experience, that piece is (often) required. Again, I ask: have you tried navigating to the URL in your code and seeing if you get a valid WSDL response? I wager you're not.
This is indeed the case and soap is waiting for this information. Otherwise, how will he know about the methods? Apparently, this is not implemented in this project.
This works for me and gives me the following output:
It worked for me too. Thank you very much, indeed, the formation of a direct request works well. This should be added to the example. blob/development/contrib/soap
I'm closing it as Resolved.