Узел Js печатает [объект Object] не печатает информацию о сеансе - PullRequest
0 голосов
/ 04 октября 2018

Я использую следующий код Node J для использования веб-службы.Но когда я запускаю это на Postman, я получаю [object Object] в консоли.Но когда я запускаю SoapUI, он выводит сведения о сеансе

мой код

router.post("/register", upload.single('image'), function (req, res, next)
{
  var url = 'http://smeapps.mobitel.lk:8585/EnterpriseSMSV2/EnterpriseSMSWS?wsdl';

  var session = {username: 'username', password: 'password'} 

  soap.createClient(url, function(err, client)
  {
    if(err)
    console.log(err)
    client.createSession(session, function(err, result)
    {
      console.log(result);
    });

  })
})

запрос сеанса SoapUI

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.esms.mobitel.lk/">
   <soapenv:Header/>
   <soapenv:Body>
      <ws:createSession>
         <!--Optional:-->
         <arg0>
            <!--Optional:-->
            <customer>12</customer>
            <!--Optional:-->
            <id>12</id>
            <!--Optional:-->
            <password>password</password>
            <!--Optional:-->
            <username>username</username>
         </arg0>
      </ws:createSession>
   </soapenv:Body>
</soapenv:Envelope>

Ответ SoapUI

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.esms.mobitel.lk/">
   <SOAP-ENV:Body>
      <ns1:createSessionResponse>
         <return>
            <expiryDate>2018-10-04T06:24:25+05:30</expiryDate>
            <isActive>true</isActive>
            <sessionId>761033662786</sessionId>
            <user>0</user>
         </return>
      </ns1:createSessionResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

обернуть код в try catch

Error: SOAP-ENV:Server: Procedure 'createSession' not present
{"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:Server</faultcode><faultstring>Procedure 'createSession' not present</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>\n","headers":{"date":"Thu, 04 Oct 2018 08:51:04 GMT","server":"Apache/2.2.15
(CentOS)","x-powered-by":"PHP/5.3.3","content-length":"304","connection":"close","content-type":"text/xml; charset=utf-8"},"request":{"uri":{"protocol":"http:","slashes":true,"auth":null,"host":"202.129.232.190:8585","port":"8585","hostname":"202.129.232.190","hash":null,"search":null,"query":null,"pathname":"/EnterpriseSMSV2/EnterpriseSMSWS.php","path":"/EnterpriseSMSV2/EnterpriseSMSWS.php","href":"http://202.129.232.190:8585/EnterpriseSMSV2/EnterpriseSMSWS.php"},"method":"POST","headers":{"User-Agent":"node-soap/0.8.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":"202.129.232.190:8585","Content-Length":0,"Content-Type":"text/xml; charset=utf-8","SOAPAction":"\"\""}}}

1 Ответ

0 голосов
/ 04 октября 2018

Кажется, вы запрашиваете REST API.

Response format for SOAP UI is XML. Но для REST API is JSON.Тогда вы получаете ответ в формате JSON.Вот почему вы получаете [object object], когда вы пытаетесь напечатать это.Посмотрите, как работать с JSON.

...