在Node js中调用SOAP API并获取错误

时间:2017-02-17 04:32:21

标签: node.js soap

我正在使用以下代码来调用Soap API在节点js中但是我没有回应,但是当我在java中使用这个api时,我会使用上面的xml数据正确地回复* .Below是我正在使用的代码。请给我正确的代码。我的代码如下,我正在使用npm模块soap来处理它

var Client = require('node-rest-client').Client;
        var client = new Client();

        // request and response additional configuration 
        var args = {

            headers: { "test-header": "client-api" },
            data: "<xml><NMFIIService><service_request><appln_id>MFS37314 </appln_id><broker_code>ARN-37314</broker_code><password>QC1RA3CJ</password><user_type>Broker</user_type><broker_loc_code>M3</broker_loc_code><iin>5011164069</iin><sub_trxn_type>N</sub_trxn_type><poa>Y</poa><trxn_acceptance>OL</trxn_acceptance><demat_user>N</demat_user><dp_id></dp_id><bank>ICI</bank><ac_no>017701520489</ac_no><ifsc_code>ICIC0000177</ifsc_code><sub_broker_arn_code></sub_broker_arn_code><sub_broker_code></sub_broker_code><euin_opted>Y</euin_opted><euin>E049164</euin><trxn_execution>Y</trxn_execution><remarks>test</remarks><payment_mode>OL</payment_mode><billdesk_bank>ICI</billdesk_bank><instrm_bank></instrm_bank><instrm_ac_no></instrm_ac_no><instrm_no></instrm_no><instrm_amount>1</instrm_amount><instrm_date></instrm_date><instrm_branch></instrm_branch><instrm_charges></instrm_charges><micr></micr><rtgs_code></rtgs_code><neft_ifsc></neft_ifsc><advisory_charge></advisory_charge><dd_charge></dd_charge><cheque_deposit_mode></cheque_deposit_mode><debit_amount_type></debit_amount_type><nominee_flag>C</nominee_flag><no_of_nominee>1</no_of_nominee><nominee1_name>BHAVNA KHATRI</nominee1_name><nominee1_dob></nominee1_dob><nominee1_addr1>C-5/5 SCOND FLOOR ARCEE CITY SECTOR 52 GURGAON</nominee1_addr1><nominee1_addr2></nominee1_addr2><nominee1_addr3></nominee1_addr3><nominee1_city>GURGAON</nominee1_city><nominee1_state></nominee1_state><nominee1_pincode></nominee1_pincode><nominee1_relation>SPOUSE</nominee1_relation><nominee1_percent>100</nominee1_percent><nominee1_guard_name></nominee1_guard_name><nominee1_guard_pan></nominee1_guard_pan><nominee2_name></nominee2_name><nominee2_dob></nominee2_dob><nominee2_relation></nominee2_relation><nominee2_percent></nominee2_percent><nominee2_guard_name></nominee2_guard_name><nominee2_guard_pan></nominee2_guard_pan><nominee3_Name></nominee3_Name><nominee3_dob></nominee3_dob><nominee3_relation></nominee3_relation><nominee3_percent></nominee3_percent><nominee3_guard_name></nominee3_guard_name><nominee3_guard_pan></nominee3_guard_pan><sip_paymech></sip_paymech><sip_micr_no></sip_micr_no><sip_bank></sip_bank><sip_branch></sip_branch><sip_instrm_no></sip_instrm_no><sip_acc_no></sip_acc_no><sip_ac_type></sip_ac_type><sip_ifsc_code></sip_ifsc_code><umrn></umrn><ach_amt></ach_amt><ach_fromdate></ach_fromdate><ach_enddate></ach_enddate><until_cancelled></until_cancelled><Return_paymnt_flag>Y</Return_paymnt_flag><Client_callback_url>http://m.investwell.in/hcver3b/pages/netbanking.jsp</Client_callback_url><trans_count>1</trans_count></service_request><childtrans><amc>128</amc><folio></folio><product_code>EFGPGGR</product_code><reinvest>Z</reinvest><amount>1</amount><sip_from_date></sip_from_date><sip_end_date></sip_end_date><sip_freq></sip_freq><sip_amount>1</sip_amount><sip_period_day></sip_period_day></childtrans></NMFIIService></xml>",
                requestConfig: {
                timeout: 1000, //request timeout in milliseconds 
                noDelay: true, //Enable/disable the Nagle algorithm 
                keepAlive: true, //Enable/disable keep-alive functionalityidle socket. 
                keepAliveDelay: 1000 //and optionally set the initial delay before the first keepalive probe is sent 
            },
            responseConfig: {
                timeout: 1000 //response timeout 
            }
        };


        client.get("https://www.nsenmf.com/NMFIITrxnService/NMFTrxnService/PURCHASETRXN", args, function (data, response) {
            // parsed response body as js object 
            console.log(data);
            // raw response 
            console.log(response);
        });

**我没有从他们的网站得到回应我应该尝试哪种方法请建议我 而我正在低于错误 **

<Buffer ef bb bf 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 75 74 66 2d 38 22 3f 3e 0d 0a 3c 21 44 4f 43 54 59 ... >
IncomingMessage {
  _readableState: 
   ReadableState {
     objectMode: false,
     highWaterMark: 16384,
     buffer: BufferList { head: null, tail: null, length: 0 },
     length: 0,
     pipes: null,
     pipesCount: 0,
     flowing: true,
     ended: true,
     endEmitted: true,
     reading: false,
     sync: false,
     needReadable: false,
     emittedReadable: false,
     readableListening: false,
     resumeScheduled: false,
     defaultEncoding: 'utf8',
     ranOut: false,
     awaitDrain: 0,
     readingMore: false,
     decoder: null,
     encoding: null },
  readable: false,
  domain: null,
  _events: 
   { end: [ [Function: responseOnEnd], [Function] ],
     timeout: [Function],
     data: [Function],
     error: [Function] },
  _eventsCount: 4,
  _maxListeners: undefined,
  socket: 
   TLSSocket {
     _tlsOptions: 
      { pipe: null,
        secureContext: [Object],
        isServer: false,
        requestCert: true,
        rejectUnauthorized: true,
        session: undefined,
        NPNProtocols: undefined,
        ALPNProtocols: undefined,
        requestOCSP: undefined },
     _secureEstablished: true,
     _securePending: false,
     _newSessionPending: false,
     _controlReleased: true,
     _SNICallback: null,
     servername: null,
     npnProtocol: undefined,
     alpnProtocol: false,
     authorized: true,
     authorizationError: null,
     encrypted: true,
     _events: 
      { close: [Object],
        end: [Object],
        finish: [Function: onSocketFinish],
        _socketEnd: [Function: onSocketEnd],
        secure: [Function],
        free: [Function: onFree],
        agentRemove: [Function: onRemove],
        drain: [Function: ondrain],
        error: [Function: socketErrorListener],
        timeout: [Object] },
     _eventsCount: 10,
     connecting: false,
     _hadError: false,
     _handle: null,
     _parent: null,
     _host: 'www.nsenmf.com',
     _readableState: 
      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: [Object],
        length: 0,
        pipes: null,
        pipesCount: 0,
        flowing: true,
        ended: false,
        endEmitted: false,
        reading: true,
        sync: false,
        needReadable: true,
        emittedReadable: false,
        readableListening: false,
        resumeScheduled: false,
        defaultEncoding: 'utf8',
        ranOut: false,
        awaitDrain: 0,
        readingMore: true,
        decoder: null,
        encoding: null },
     readable: false,
     domain: null,
     _maxListeners: undefined,
     _writableState: 
      WritableState {
        objectMode: false,
        highWaterMark: 16384,
        needDrain: false,
        ending: true,
        ended: true,
        finished: true,
        decodeStrings: false,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: false,
        bufferProcessing: false,
        onwrite: [Function],
        writecb: null,
        writelen: 0,
        bufferedRequest: null,
        lastBufferedRequest: null,
        pendingcb: 0,
        prefinished: true,
        errorEmitted: false,
        bufferedRequestCount: 0,
        corkedRequestsFree: [Object] },
     writable: false,
     allowHalfOpen: false,
     destroyed: true,
     _bytesDispatched: 3021,
     _sockname: null,
     _pendingData: null,
     _pendingEncoding: '',
     server: undefined,
     _server: null,
     ssl: null,
     _requestCert: true,
     _rejectUnauthorized: true,
     parser: null,
     _httpMessage: 

  responseUrl: 'https://www.nsenmf.com',
  read: [Function] }


I am not trying other code . Please suggest me right way to achieve it

1 个答案:

答案 0 :(得分:0)

您正在进行GET,这意味着您为正文设置的所有数据都不会传递给您正在调用的服务器。尝试切换到client.post而不是client.get

有关详细信息,请参阅the documentation for node-rest-client

此外,您正在尝试使用REST组件调用SOAP服务。虽然它仍然可行,但传统上你需要添加诸如SOAPAction之类的东西并自己构建你的SOAP信封,而使用专用的SOAP组件 - 例如node-soap - 意味着你可以专注于使用服务不必过多担心请求结构。