我正在使用给定的SOAP-API来请求一些东西。该API有充分的文档记录,但是所有示例都是用PHP编写的,而不是我偏爱的语言。我在PHP中的所有实现都可以使用,但是现在我想在ExpressJS-Service中实现并将其集成。我正在使用流行的NodeJS-SOAP-Library,并且请求数据完全相同。但是对API的请求返回以下错误消息:
<?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>session_lifetime_syntax_incorrect:w</faultstring><faultactor>KasAuth</faultactor>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>\n
生成的请求正文如下:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="https://kasserver.com/">
<soap:Body>
<tns:KasAuth><KasUser>[username]</KasUser>
<KasAuthType>sha1</KasAuthType>
<KasPassword>[password-hash]</KasPassword>
<SessionLifeTime>600</SessionLifeTime>
<SessionUpdateLifeTime>Y</SessionUpdateLifeTime>
</tns:KasAuth>
</soap:Body>
</soap:Envelope>
我的JavaScript代码如下:
var soap = require('soap');
var sha1 = require('js-sha1');
var password = sha1('[password]');
var url = '[api-url].wsdl';
var args = {
KasUser: '[username]',
KasAuthType: 'sha1',
KasPassword: password,
SessionLifeTime: 600,
SessionUpdateLifeTime: 'Y'
};
soap.createClient(url, function(err, client) {
client.KasAuth(args, function(err, result) {
console.log(result);
});
});
我正在工作的PHP代码如下:
...
$session_lifetime = 600;
$session_update_lifetime = 'Y';
...
try
{
$SoapLogon = new SoapClient('[api-url].wsdl');
$CredentialToken = $SoapLogon->KasAuth(json_encode(array(
'KasUser' => $kas_user,
'KasAuthType' => 'sha1',
'KasPassword' => sha1($kas_pass),
'SessionLifeTime' => $session_lifetime,
'SessionUpdateLifeTime' => $session_update_lifetime
)));
header('Content-Type: application/json');
echo(json_encode(array('token' => $CredentialToken), JSON_PRETTY_PRINT));
}
// Fehler abfangen und ausgeben
catch (SoapFault $fault)
{
trigger_error("Fehlernummer: {$fault->faultcode},
Fehlermeldung: {$fault->faultstring},
Verursacher: {$fault->faultactor},
Details: {$fault->detail}", E_USER_ERROR);
}
我正在使用的PHP代码的请求正文:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:xmethodsKasApiAuthentication" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:KasAuth>
<Params xsi:type="xsd:string">{"KasUser":[username],"KasAuthType":"sha1","KasPassword":[password-hash],"SessionLifeTime":600,"SessionUpdateLifeTime":"Y"}</Params>
</ns1:KasAuth>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
登录密码相同。
我试图将SessionLifeTime的值更改为600.0和'600'...
API提供者不知道可能出什么问题。
更新: 我看到请求主体是不同的,但是我不知道如何在节点肥皂中更改它。
答案 0 :(得分:1)
最大的区别是php版本将所有params转换为json字符串并将其填充到Params元素中,而js版本将js对象编码为xml。我会用类似JSON.stringify(args)}的方式使js端匹配。