Home > Article > Web Front-end > Problem analysis of nodejs implementation of webservice
The content of this article is about the analysis of the problem of nodejs implementing webservice. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Library, tool
node-soap
soapui
Create
Note the order of parameters in args
const soap = require('soap'); let URL = "你的wsdl路径,可以是url或者本地文件"; // 注意参数顺序!!!!!!!!! let args = { key1: val1, key2: val2 }; // promise创建 let client = await soap.createClientAsync(URL); // callback创建 soap.createClient(url, function(err, client) { client.MyFunction(args, function(err, result) { console.log(result); }); });
I personally like the promise form. Calling other functions can be implemented in two ways. If it is asynchronous, you need to add "Async" after the function name you call.
There is nothing special about having only one layer of parameter data, such as:
args = { key1: val1, key2: val2 }
If there is another layer in the parameter, node-soap will not automatically generate the band based on wsdl Data with namespace prefix will fail to parse XML after being transmitted to the server.
For example:
let val2: Array<datatype> = [ { key3: val3 } ]; let args = { key1: val1, key2: val2 }</datatype>
At this time, you need to do some extra work when passing in the data. Change it to:
let val2: Array<datatype> = [ { key3: val3 } ]; let args = { key1: val1, key2: { dataType: val2 } }</datatype>
The above dataType is the type when generating xml. There is a declaration in xml; if there is no declaration, it is written in another way, such as:
// dataType或namespace prefix在生成xml未声明 let val2: Array<datatype> = [ { key3: val3 } ]; let args = { key1: val1, key2: val2 }</datatype>
needs to be rewritten as (Array
let val2: Array<string> = [ val3, val4 ]; let args = { attributes: { 'xmlns:arr': 'http://schemas.microsoft.com/2003/10/Serialization/Arrays' }, key1: val1, key2: { "arr:string": val2 } }</string>
https://stackoverflow.com/que...
16 times to read It takes 6 minutes to read
1
Libraries, toolsnode-soapsoapuiCreate
Pay attention to the order of parameters in argsconst soap = require('soap'); let URL = "你的wsdl路径,可以是url或者本地文件"; // 注意参数顺序!!!!!!!!! let args = { key1: val1, key2: val2 }; // promise创建 let client = await soap.createClientAsync(URL); // callback创建 soap.createClient(url, function(err, client) { client.MyFunction(args, function(err, result) { console.log(result); }); });
Personally, I like the promise form. Subsequent calls to other functions can be implemented in two ways. If it is asynchronous, you need to add "Async" after the function name you call.
Call
args = { key1: val1, key2: val2 }
For example:
let val2: Array<datatype> = [ { key3: val3 } ]; let args = { key1: val1, key2: val2 }</datatype>At this time, you need to do some extra work when passing in the data. Change it to:
let val2: Array<datatype> = [ { key3: val3 } ]; let args = { key1: val1, key2: { dataType: val2 } }</datatype>The above dataType is the type when generating xml. There is a declaration in xml; if there is no declaration, it is written in another way, such as:
// dataType或namespace prefix在生成xml未声明 let val2: Array<datatype> = [ { key3: val3 } ]; let args = { key1: val1, key2: val2 }</datatype>
let val2: Array<string> = [ val3, val4 ]; let args = { attributes: { 'xmlns:arr': 'http://schemas.microsoft.com/2003/10/Serialization/Arrays' }, key1: val1, key2: { "arr:string": val2 } }</string>https://stackoverflow.com/que...
report
Comment
Sort by timeShow more comments
The above is the detailed content of Problem analysis of nodejs implementation of webservice. For more information, please follow other related articles on the PHP Chinese website!