我通过Nodejs使用了SOAP Web服务:
$(document).ready(function() {
$.ajax({
url: "/track/vehicule/getWebserviceRetourKYC",
type: "POST",
success : function(data, status, xhr) {
console.dir(data);
},
error : function(xhr, status, error) {
console.dir(error);
}
});
});
var express = require('express');
var request = require("request");
var fs = require('fs');
var path = require('path');
var async = require('async');
var router = express.Router();
var db = require('./db');
var utils = require('./utils');
var connexion = db.getConnexion();
router.post("/getWebserviceRetourKYC", function(req, res) {
var soap = require('strong-soap').soap;
// wsdl of the web service this client is going to invoke. For local wsdl you can use, url = './wsdls/stockquote.wsdl'
var url = "https://www.telma.net/sentimsa/mvola/wsdl.php?module=jWSDL&action=WSDL:wsdl&service=mvola~WSMVolaGetInfosKYC";
var requestArgs = {
module:'jWSDL',
action:'WSDL:wsdl',
service:'mvola~WSMVolaGetInfosKYC'
};
var options = {};
soap.createClient(url, options, function(err, client) {
var method = client['WSMVolaGetInfosKYCCtrl']['WSMVolaGetInfosKYCCtrlPort']['getInfosKYC'];
console.dir(client);//here
method(requestArgs, function(err, result, envelope, soapHeader) {
//response envelope
console.log('Response Envelope: \n' + envelope);
//'result' is the response body
console.log('Result: \n' + JSON.stringify(result));
});
});
res.send();
});
module.exports = router;
在运行时返回的结果是:
{
"statusCode": 500,
"body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Client<\/faultcode><faultstring>Error cannot find parameter<\/faultstring><\/SOAP-ENV:Fault><\/SOAP-ENV:Body><\/SOAP-ENV:Envelope>\n",
"headers":
{
"date": "Thu, 04 Jul 2019 05:51:26 GMT",
"server": "Apache/2.2.3 (Red Hat)",
"content-length": "294",
"content-type": "text/xml; charset=utf-8",
"content-language": "en",
"connection": "close"
},
"request":
{
"uri":
{
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "www.telma.net",
"port": 443,
"hostname": "www.telma.net",
"hash": null,
"search": "?service=mvola%7EWSMVolaGetInfosKYC",
"query": "service=mvola%7EWSMVolaGetInfosKYC",
"pathname": "/sentimsa/mvola/soap.php",
"path": "/sentimsa/mvola/soap.php?service=mvola%7EWSMVolaGetInfosKYC",
"href": "https://www.telma.net/sentimsa/mvola/soap.php?service=mvola%7EWSMVolaGetInfosKYC"
},
"method": "POST",
"headers":
{
"User-Agent": "strong-soap/1.20.0",
"Accept": "text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8",
"Accept-Encoding": "none",
"Accept-Charset": "utf-8",
"Connection": "close",
"Host": "www.telma.net",
"Content-Length": 396,
"Content-Type": "text/xml; charset=utf-8",
"SOAPAction": "\"https://www.telma.net/sentimsa/mvola/soap.php?service=mvola%7EWSMVolaGetInfosKYC&method=getInfosKYC\""
}
}
}
那么我的代码有什么问题呢?
------编辑------:
以下是信封和所需结果的示例:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mvol="https://www.telma.net/sentimsa/mvola/">
<soapenv:Header/>
<soapenv:Body>
<mvol:getInfosKYC soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<zSubscriberId xsi:type="xsd:string"> 0340017729</zSubscriberId>
</mvol:getInfosKYC>
</soapenv:Body>
</soapenv:Envelope>
响应:
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://www.telma.net/sentimsa/mvola/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getInfosKYCResponse>
<getInfosKYCReturn xsi:type="ns1:CCodeReponse">
<oDataKYC xsi:nil="true" xsi:type="ns1:CKycInfos"/>
<status_Code xsi:type="xsd:string">101</status_Code>
<status_Reason xsi:type="xsd:string">Le numéro 0340017728 n’existe pas dans Sentinel.</status_Reason>
</getInfosKYCReturn>
</ns1:getInfosKYCResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
答案 0 :(得分:0)
错误:
<faultstring>Error cannot find parameter<\/faultstring>
建议您在请求中缺少必需的参数。您是否有正在使用的SOAP服务的文档? module
,action
和service
是唯一必需的参数吗?
此外,您还在URL字符串中包括了这些参数:
var url = "https://www.telma.net/sentimsa/mvola/wsdl.php?module=jWSDL&action=WSDL:wsdl&service=mvola~WSMVolaGetInfosKYC";
不确定这是否会导致问题,但至少不需要。我会尝试从网址字符串中删除这些参数。