Home > Web Front-end > JS Tutorial > body text

Problem analysis of nodejs implementation of webservice

不言
Release: 2019-02-28 13:32:25
forward
3781 people have browsed it

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);
    });
});
Copy after login
Copy after login

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.

Call

There is nothing special about having only one layer of parameter data, such as:

args = {
    key1: val1,
    key2: val2
}
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

needs to be rewritten as (Array is used here to refer to the namespace prefix generated by soapui, and other types are specified. The implementation should be universal);

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>
Copy after login
Copy after login
https://stackoverflow.com/que...







#                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           Posted 20 hours ago

16 times to read                                                             It takes 6 minutes to read                                                                                                                           



## 1                       

                                                                                                                                                                                                                                                                                                                                                                                  Libraries, toolsnode-soapsoapuiCreate

Pay attention to 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);
    });
});
Copy after login
Copy after login

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

There is nothing special about having only one layer of parameter data, such as:

args = {
    key1: val1,
    key2: val2
}
Copy after login
Copy after login

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>
Copy after login
Copy after login
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>
Copy after login
Copy after login
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>
Copy after login
Copy after login

needs to be rewritten as (Array is used here to refer to the namespace prefix generated by soapui, and other types are specified. The implementation should be universal);

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>
Copy after login
Copy after login
https://stackoverflow.com/que...

  • Problem analysis of nodejs implementation of webservicereport

You may be interested


Comment

                                                                                           Sort by time



Loading...

Show 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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!