简而言之,大约有100个soap web服务,我需要通过NodeJ将它们作为其余部分公开。我的意思是,对于每个肥皂服务,都会有一个休息服务扮演立面角色。
我安装" npm install soap"正如https://github.com/vpulim/node-soap和https://github.com/23/node-soap中所述。以下示例工作正常,因此我了解安装正常。
所以,我的问题是:我怎样才能阅读下面的wsdl?请注意,通过跟随成功示例看看我是如何尝试的,并且我得到了某些错误,似乎我在" client.CadastroService.CadastroServiceSoapBinding.consultarDados"中缺少一些额外的词。好吧,这个例子中的wdls与我的wsdl有一点不同。该示例依赖于" wsdl:input wsaw:Action = ..."而我的并没有使用wsaw:就是行动。我想它并没有改变我调用它的方式。我按照这种模式打电话:" wsdl:服务名称"。" wsdl:绑定名称"。" wsdl:消息名称"
工作示例:
var soap = require('soap');
var url = "http://www.restfulwebservices.net/wcf/StockQuoteService.svc?wsdl";
var args = {"tns:request":"GOOG"};
soap.createClient(url, function(err, client){
client.CadastroService.BasicHttpBinding_IStockQuoteService.GetStockQuote(args, function(err, result){
if (err) throw err;
console.log(result);
});
});
我的wsdl(显然编辑为更简单):
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://service.ws.mycompany.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="CadastroService" targetNamespace="http://service.ws.mycompany.com/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://service.ws.mycompany.com/" elementFormDefault="unqualified" targetNamespace="http://service.ws.mycompany.com/" version="1.0">
<xs:element name="consultarDados" type="tns:consultarDados"/>
<xs:element name="root" nillable="true" type="xs:anyType"/>
<xs:complexType name="basicResponse">
<xs:sequence>
<xs:element minOccurs="0" name="codigoRetorno" type="xs:string"/>
<xs:element minOccurs="0" name="mensagemRetorno" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="consultarDados">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="tns:ConsultarInput"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ConsultarInput">
<xs:sequence>
<xs:element minOccurs="0" name="numCartao" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="consultarDadosResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="tns:ConsultarResponse"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ConsultarResponse">
<xs:complexContent>
<xs:extension base="tns:basicResponse">
<xs:sequence>
<xs:element minOccurs="0" name="blockCode" type="xs:string"/>
<xs:element minOccurs="0" name="blockCode2" type="xs:string"/>
<xs:element minOccurs="0" name="codBloqueioBoletimProtecao" type="xs:string"/>
<xs:element minOccurs="0" name="codLogo" type="xs:string"/>
<xs:element minOccurs="0" name="codMotivoEmissao2via" type="xs:string"/>
<xs:element minOccurs="0" name="codProdutoDN" type="xs:string"/>
<xs:element minOccurs="0" name="dataAberturaConta" type="xs:string"/>
<xs:element minOccurs="0" name="dataCancelamento" type="xs:string"/>
<xs:element minOccurs="0" name="dataEmissaoCartao" type="xs:string"/>
<xs:element minOccurs="0" name="dataExclusaoBoletimProtecao" type="xs:string"/>
<xs:element minOccurs="0" name="dataExpiracaoConta" type="xs:string"/>
<xs:element minOccurs="0" name="dataGeracaoPlastico" type="xs:string"/>
<xs:element minOccurs="0" name="dataInclusaoBoletimProtecao" type="xs:string"/>
<xs:element minOccurs="0" name="dataInicioAtraso" type="xs:string"/>
<xs:element minOccurs="0" name="dataNascimento" type="xs:string"/>
<xs:element minOccurs="0" name="dataProximoCorte" type="xs:string"/>
<xs:element minOccurs="0" name="dataProximoVencto" type="xs:string"/>
<xs:element minOccurs="0" name="dataUltimaAlteracaoLimite" type="xs:string"/>
<xs:element minOccurs="0" name="dataUltimaAlteracaoVencto" type="xs:string"/>
<xs:element minOccurs="0" name="dataUltimoPagamento" type="xs:string"/>
<xs:element minOccurs="0" name="dataValidadePlastico" type="xs:string"/>
<xs:element minOccurs="0" name="dataVenctoPenultimaFatura" type="xs:string"/>
<xs:element minOccurs="0" name="dataVenctoUltFatura" type="xs:string"/>
<xs:element minOccurs="0" name="dddCelular1" type="xs:string"/>
<xs:element minOccurs="0" name="dddCelular2" type="xs:string"/>
<xs:element minOccurs="0" name="dddComercial" type="xs:string"/>
<xs:element minOccurs="0" name="dddResidencial" type="xs:string"/>
<xs:element minOccurs="0" name="ddiCelular1" type="xs:string"/>
<xs:element minOccurs="0" name="ddiCelular2" type="xs:string"/>
<xs:element minOccurs="0" name="ddiComercial" type="xs:string"/>
<xs:element minOccurs="0" name="ddiResidencial" type="xs:string"/>
<xs:element minOccurs="0" name="descTipoPessoa" type="xs:string"/>
<xs:element minOccurs="0" name="diaCorteAtual" type="xs:string"/>
<xs:element minOccurs="0" name="diaVencimento" type="xs:string"/>
<xs:element minOccurs="0" name="endereco" type="xs:string"/>
<xs:element minOccurs="0" name="enderecoBairro" type="xs:string"/>
<xs:element minOccurs="0" name="enderecoCEP" type="xs:string"/>
<xs:element minOccurs="0" name="enderecoCidade" type="xs:string"/>
<xs:element minOccurs="0" name="enderecoComplemento" type="xs:string"/>
<xs:element minOccurs="0" name="enderecoNumero" type="xs:string"/>
<xs:element minOccurs="0" name="enderecoUF" type="xs:string"/>
<xs:element minOccurs="0" name="estadoCivilDesc" type="xs:string"/>
<xs:element minOccurs="0" name="flagTipoFaturamento" type="xs:string"/>
<xs:element minOccurs="0" name="indClienteVip" type="xs:string"/>
<xs:element minOccurs="0" name="indClienteVipDesc" type="xs:string"/>
<xs:element minOccurs="0" name="indDebitoAutomatico" type="xs:string"/>
<xs:element minOccurs="0" name="indEstadoCivil" type="xs:string"/>
<xs:element minOccurs="0" name="indLimiteSegregado" type="xs:string"/>
<xs:element minOccurs="0" name="indSexo" type="xs:string"/>
<xs:element minOccurs="0" name="indicadorCartaoBloqueado" type="xs:string"/>
<xs:element minOccurs="0" name="indicadorCartaoOuConta" type="xs:string"/>
<xs:element minOccurs="0" name="indicadorCompraParcelada" type="xs:string"/>
<xs:element minOccurs="0" name="indicadorContato" type="xs:string"/>
<xs:element minOccurs="0" name="indicadorTeleSaque" type="xs:string"/>
<xs:element minOccurs="0" name="nomeMae" type="xs:string"/>
<xs:element minOccurs="0" name="nomeOrg" type="xs:string"/>
<xs:element minOccurs="0" name="nomePai" type="xs:string"/>
<xs:element minOccurs="0" name="nomePortator" type="xs:string"/>
<xs:element minOccurs="0" name="numCartaoAnterior" type="xs:string"/>
<xs:element minOccurs="0" name="numCartaoTitular" type="xs:string"/>
<xs:element minOccurs="0" name="numCelular1" type="xs:string"/>
<xs:element minOccurs="0" name="numCelular2" type="xs:string"/>
<xs:element minOccurs="0" name="numChpras" type="xs:string"/>
<xs:element minOccurs="0" name="numComercial" type="xs:string"/>
<xs:element minOccurs="0" name="numConta" type="xs:string"/>
<xs:element minOccurs="0" name="numCpfCnpj" type="xs:string"/>
<xs:element minOccurs="0" name="numOrg" type="xs:string"/>
<xs:element minOccurs="0" name="numRG" type="xs:string"/>
<xs:element minOccurs="0" name="numResidencial" type="xs:string"/>
<xs:element name="qtdAdicionais" type="xs:int"/>
<xs:element name="qtdCompraParceladaAtual" type="xs:int"/>
<xs:element name="qtdDiasAtrasoUltimaFatura" type="xs:int"/>
<xs:element minOccurs="0" name="qtdVezesFaturamentoConta" type="xs:string"/>
<xs:element name="saldoAFaturar" type="xs:double"/>
<xs:element name="saldoAntepenultimaFatura" type="xs:double"/>
<xs:element name="saldoCompraInter" type="xs:double"/>
<xs:element name="saldoFaturaFechada" type="xs:double"/>
<xs:element name="saldoInterFatura" type="xs:double"/>
<xs:element name="saldoInterUltimaFaturaFechada" type="xs:double"/>
<xs:element minOccurs="0" name="sexoDesc" type="xs:string"/>
<xs:element minOccurs="0" name="situacaoConta" type="xs:string"/>
<xs:element minOccurs="0" name="situacaoContaDesc" type="xs:string"/>
<xs:element name="taxaCashProxPeriodo" type="xs:double"/>
<xs:element name="taxaJurosProxPeriodo" type="xs:double"/>
<xs:element minOccurs="0" name="tipoCartao" type="xs:string"/>
<xs:element minOccurs="0" name="tipoPessoa" type="xs:string"/>
<xs:element minOccurs="0" name="tipoPortador" type="xs:string"/>
<xs:element minOccurs="0" name="tipoPortadorDesc" type="xs:string"/>
<xs:element name="totalCashAFaturar" type="xs:double"/>
<xs:element name="valorAtraso" type="xs:double"/>
<xs:element name="valorLimiteCash" type="xs:double"/>
<xs:element name="valorLimiteCashInter" type="xs:double"/>
<xs:element name="valorLimiteCredito" type="xs:double"/>
<xs:element name="valorLimiteCreditoInter" type="xs:double"/>
<xs:element name="valorLimiteDispCash" type="xs:double"/>
<xs:element name="valorLimiteDispCashInter" type="xs:double"/>
<xs:element name="valorLimiteDispCredito" type="xs:double"/>
<xs:element name="valorLimiteDispCreditoInter" type="xs:double"/>
<xs:element name="valorLimiteParcDisponivelSegregado" type="xs:double"/>
<xs:element name="valorLimiteParcTotalSegregado" type="xs:double"/>
<xs:element name="valorPagtoMinimoUltFatura" type="xs:double"/>
<xs:element name="valorUltimoPagamento" type="xs:double"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="consultarDados">
<wsdl:part element="tns:consultarDados" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="Cadastro">
<wsdl:operation name="consultarDados">
<wsdl:input message="tns:consultarDados" name="consultarDados">
</wsdl:input>
<wsdl:output message="tns:consultarDadosResponse" name="consultarDadosResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CadastroServiceSoapBinding" type="tns:Cadastro">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="consultarDados">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="consultarDados">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="consultarDadosResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CadastroService">
<wsdl:port binding="tns:CadastroServiceSoapBinding" name="CadastroPort">
<soap:address location="http://myip...:myport/ws-myapp/cadastro"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
完整错误:
demetrio@nodejs ~/dev/NodeJsSrc $ node consultaDados.js
/home/demetrio/dev/NodeJsSrc/consultaDados.js:9
client.CadastroService.CadastroServiceSoapBinding.consultarDados(args, function(err, result){
^
TypeError: Cannot read property 'consultarDados' of undefined
at /home/demetrio/dev/NodeJsSrc/consultaDados.js:9:54
at /home/demetrio/node_modules/soap/lib/soap.js:58:5
at null.callback (/home/demetrio/node_modules/soap/lib/soap.js:25:9)
at /home/demetrio/node_modules/soap/lib/wsdl.js:1073:12
at WSDL._processNextInclude (/home/demetrio/node_modules/soap/lib/wsdl.js:1148:12)
at WSDL.processIncludes (/home/demetrio/node_modules/soap/lib/wsdl.js:1191:8)
at /home/demetrio/node_modules/soap/lib/wsdl.js:1028:10
at nextTickCallbackWith0Args (node.js:419:9)
at process._tickCallback (node.js:348:13)
demetrio@nodejs ~/dev/NodeJsSrc $
我是如何阅读soap web服务的(我基本上按照上面的示例工作)
var soap = require('soap');
var url = "http://myIp...:myPort/ws-myApp/cadastro?wsdl";
var args = {"tns:request":"GOOG"};
soap.createClient(url, function(err, client){
client.CadastroService.CadastroServiceSoapBinding.consultarDados(args, function(err, result){
if (err) throw err;
console.log(result);
});
});