节点Js打印[对象Object]不打印会话信息

时间:2018-10-04 05:19:20

标签: node.js soap soapui

我正在使用以下Node Js代码来使用Web服务。但是,当我在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 :(得分:0)

似乎您正在请求REST API。

Response format for SOAP UI is XML.但是对于REST API is JSON。然后,您将获得JSON格式的响应。这就是为什么您尝试打印时得到[object object]的原因。因此,请查看如何处理JSON。