javascript - Node JS : SOAP to query Java Web Services

标签 javascript node.js soap-client

我正在尝试从 Node js 模块调用 Javaweb 服务。但是,我在 wsdl 库中遇到错误。这是我的 wsdl 文件。

<!--
 Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. 
--><!--
 Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. 
--><definitions targetNamespace="http://jaxws.joshis1.com/" name="webServiceImplService"><types><xsd:schema><xsd:import namespace="http://jaxws.joshis1.com/" schemaLocation="http://localhost:8888/webservice/helloworld?xsd=1"/></xsd:schema></types><message name="sayHello"><part name="parameters" element="tns:sayHello"/></message><message name="sayHelloResponse"><part name="parameters" element="tns:sayHelloResponse"/></message><portType name="IwebServiceInterface"><operation name="sayHello"><input wsam:Action="http://jaxws.joshis1.com/IwebServiceInterface/sayHelloRequest" message="tns:sayHello"/><output wsam:Action="http://jaxws.joshis1.com/IwebServiceInterface/sayHelloResponse" message="tns:sayHelloResponse"/></operation></portType><binding name="webServiceImplPortBinding" type="tns:IwebServiceInterface"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><operation name="sayHello"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation></binding><service name="webServiceImplService"><port name="webServiceImplPort" binding="tns:webServiceImplPortBinding"><soap:address location="http://localhost:8888/webservice/helloworld"/></port></service></definitions>

这是我的 test.js

  var soap = require('soap');
  var url = 'http://localhost:8888/webservice/helloworld?wsd';
  var args = {sayHello: 'ABC'};
  soap.createClient(url, function(err, client) {
      client.MyFunction(args, function(err, result) {
          console.log(result);
      });
  }); 

运行时,出现以下错误 -

node_modules/soap/lib/wsdl.js:68
  const [topLevelName] = nsName.split('|');
        ^

SyntaxError: Unexpected token [
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)

$node --版本 v4.2.6

有没有像jquery这样的其他方式来调用这个java web服务?

node test.js 
/home/sjoshi/test.js:5
      client.sayHello(args, function(err, result) {
             ^

TypeError: Cannot read property 'sayHello' of undefined

最佳答案

您使用的 Node.js 版本是什么?我相信数组解构是一个较新的功能,因此如果您运行的是旧版本的 Node.js,它可能没有此功能。

http://kangax.github.io/compat-table/es6/#node6_5

看起来 Node 6.5 及更高版本支持它。

关于javascript - Node JS : SOAP to query Java Web Services,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53861088/

相关文章:

node.js - jest.js 无法识别编码

node.js - 如何在 http 模块中收听没有 '/' 的路径

php - 在不同的命名空间 php 中调用一个函数

java - 使用 WSDL url 为参数生成 Java 类 (Pojo)

javascript - 如何检查文件是否存在于带 Angular url中?

javascript - JS : css property and value in one variable

javascript - Jquery 附加/前置 svg 并查找子元素

node.js - 错误 C2039: 'IsNearDeath' : 不是 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>> 的成员

web-services - 如何使用 FLEX 解析 SOAP 响应

javascript - Google Charts,设置条形图的网格线数