2

I am trying to get node/express to send soap request to indesign server.

Posting the request from Soap.ui or Postman works fine. Loading the "soap" page in the browser errors.

I also tried the node client with a few sample scripts from the new and they work, so the install should be OK.

This is what I have so far:

    router.get('/soap', function(req, res, next) {

      var url = 'http://<server_ip>:8088/service?wsdl';

      var args = { "IDSP:RunScriptParameters" :
                         { 'scriptLanguage': 'javascript',
                           'scriptFile': 'C:/indesign_scripts/test.jsx'
                         }
                   };


      soap.createClient(url, function(err, client){
          client.Service.Service.RunScript(args, function(err, result) {
            if (err)   console.log(err);
            console.log(result);
          });
  });

client.describe() returns:

{ Service: 
   { Service: 
      { RunScript: [Object],
        BeginSession: [Object],
        EndSession: [Object] } } }

I am trying to use RunScript object.

client.describe().Service.Service.RunScript:

{ input: 
   { runScriptParameters: 
      { scriptText: 'xsd:string',
        scriptLanguage: 'xsd:string',
        scriptFile: 'xsd:string',
        'scriptArgs[]': [Object],
        targetNSAlias: 'IDSP',
        targetNamespace: 'http://ns.adobe.com/InDesign/soap/' } },
  output: 
   { errorNumber: 'xsd:int',
     errorString: 'xsd:string',
     scriptResult: 
      { data: 'xsd:anyType',
        targetNSAlias: 'IDSP',
        targetNamespace: 'http://ns.adobe.com/InDesign/soap/' } } }

Console shows this error:

[Error: connect ECONNREFUSED 127.0.0.1:8088]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 8088 }

Indesign Server wsdl could be viewed here:

https://gist.github.com/tomtaylor/1034317

I suspect this is something with args variable format.

Nicolai Kant
  • 1,391
  • 1
  • 9
  • 23

3 Answers3

1

You can fix this issue by adding line below

client.setEndpoint('http://<server_ip>:8088');
uetkaje
  • 11
  • 1
  • it's unbealiveble how hard was to find this solution! Why the docs doesn't cover it directly? I'm surprised how easier is to do a work around with axios than using node-soap to make a simple request! But this "solved" my firewall "problem". – Kvothe Chibli Jan 27 '20 at 21:59
0

I tried to add "Access-Control-Allow-Origin" to my headers in my app file, as suggested by @Chirdeep Tomar, but I am still getting the same errors.

The workaround I came up with was to use http request or curl for ajax post.

The example with request:

var express = require('express');
var request = require('request');
var parser = require('xml2json');
var router = express.Router();

router.get('/ProductionBooks/:id', function(req, res) {

     var myId = req.params.id;

     var myBody = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://ns.adobe.com/InDesign/soap/"><soapenv:Body>'
                  +'<soap:RunScript>'
                  +'<runScriptParameters>'
                  +'<scriptLanguage>javascript</scriptLanguage>'
                  +'<scriptFile>C:/indesign_scripts/test.jsx</scriptFile>'                                   
                  +'</runScriptParameters>'
                  +'</soap:RunScript>'
                  +'</soapenv:Body>'
                  +'</soapenv:Envelope>';

      request({
                  url: 'http://192.168.0.129:8088', //URL to hit
                  method: 'POST',
                  headers: {
                      'Content-Type': 'application/xml',
                      'Content-Length': Buffer.byteLength(myBody)
                  },
                  body: myBody

              }, function(error, response, body){
                  if(error) {
                      console.log(error);
                  } else {
                      console.log(response.statusCode + '\n');
                      var objJSON = JSON.parse(parser.toJson(body));
                      console.log(objJSON['SOAP-ENV:Envelope']['SOAP-ENV:Body']['IDSP:RunScriptResponse'].errorNumber);
              }
              });

              res.end();
});

Example with curl:

var curl = require("curl");
curl.post(url, soapBody, options, function(err, response, body) {
    try {
        console.log(response.body);
    }
    catch (err) {
        console.log(err);
    }
});

res.end();

});
Nicolai Kant
  • 1,391
  • 1
  • 9
  • 23
0

using easy-soap-request:

   const soapRequest = require('easy-soap-request');
        
    const url = 'http://[YOUR SERVER ADDRESS]:[IDS PORT]/service?wsdl';
    const sampleHeaders = {
      'user-agent': 'sampleTest',
      'Content-Type': 'text/xml;charset=UTF-8',
    };
    const xml = '<?xml version="1.0" encoding="UTF-8"?>'
+'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:IDSP="http://ns.adobe.com/InDesign/soap/">'
+'<SOAP-ENV:Body><IDSP:RunScript><IDSP:runScriptParameters>'
+'<IDSP:scriptLanguage>javascript</IDSP:scriptLanguage>'
+'<IDSP:scriptFile>[PATH TO SCRIPTS]/Hello.jsx</IDSP:scriptFile>'
+'<IDSP:scriptArgs><IDSP:name>myArg</IDSP:name><IDSP:value>Test Value</IDSP:value></IDSP:scriptArgs>'
+'</IDSP:runScriptParameters></IDSP:RunScript>'
+'<IDSP:RunScriptResponse><errorNumber>0</errorNumber><scriptResult><data xsi:type="IDSP:List"><item><data xsi:type="xsd:string">1</data></item></data></scriptResult></IDSP:RunScriptResponse>'
+'</SOAP-ENV:Body></SOAP-ENV:Envelope>';
    
    // usage of module
    (async () => {
      const { response } = await soapRequest({ url: url, headers: sampleHeaders, xml: xml, timeout: 1000 }); // Optional timeout parameter(milliseconds)
      const { headers, body, statusCode } = response;
      console.log(headers);
      console.log(body);
      console.log(statusCode);
    })();

Sample script (hello.jsx):

var arg = app.scriptArgs.get("myArg");
var res = "Your input: " + arg;
res;
sketchyTech
  • 5,746
  • 1
  • 33
  • 56