node.js - Node Js打印[object Object]不打印 session 信息

标签 node.js soap soapui

我正在使用以下 Node Js 代码来使用 Web 服务。但是当我在 Postman 上运行它时,我在控制台中得到了 [object Object] 。但是当我在 SoapUI 上运行时,它会打印 session 详细信息

我的代码

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 session 请求

<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":"\"\""}}}

最佳答案

您似乎正在请求 REST API。

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

关于node.js - Node Js打印[object Object]不打印 session 信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52639495/

相关文章:

java.lang.NoClassDefFoundError : org/apache/cxf/jaxrs/impl/UriBuilderImpl 错误

wcf - OAuth 和 WCF SOAP 服务

基于返回项计数的 SoapUI JSONPath 断言

rest - 通过 ReST api 与 SOAPui 进行 VSTS 连接

node.js - 在 Webstorm 中运行 jasmine 测试会在跟踪中停止,退出代码为 0

node.js - 为什么在 Express 路线运行后我无法调用 `next`?

javascript - 使用 Browserify 导出 p5.js 函数

wcf - 什么是最简单的 WCF/SOAP 配置?

SoapUI 中的 WCF wsHttpBinding

node.js - node-forever 似乎没有按我的预期工作