2

我正在尝试让 node/express 向 indesign 服务器发送肥皂请求。

从 Soap.ui 或 Postman 发布请求可以正常工作。在浏览器错误中加载“soap”页面。

我还用新的一些示例脚本尝试了节点客户端,它们可以工作,所以安装应该没问题。

这是我到目前为止所拥有的:

    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() 返回:

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

我正在尝试使用 RunScript 对象。

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/' } } }

控制台显示此错误:

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

Indesign Server wsdl 可以在这里查看:

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

我怀疑这是 args 变量格式的问题。

4

2 回答 2

1

您可以通过在下面添加行来解决此问题

client.setEndpoint('http://<server_ip>:8088');
于 2016-07-17T11:27:11.953 回答
0

我尝试按照@Chirdeep Tomar 的建议将“Access-Control-Allow-Origin”添加到我的应用程序文件的标题中,但我仍然遇到相同的错误。

我想出的解决方法是使用 http 请求或 curl 进行 ajax 发布。

请求示例:

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();
});

卷曲示例:

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();

});
于 2016-06-07T18:01:44.647 回答