我正在尝试让node / express向soaps服务器发送soap请求。
从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变量格式的东西。
答案 0 :(得分:0)
我试图在我的app文件中添加“Access-Control-Allow-Origin”,如@Chirdeep Tomar所示,但我仍然遇到同样的错误。
我想出的解决方法是使用http请求或curl for ajax post。
请求示例:
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();
});
答案 1 :(得分:0)
您可以通过在
下面添加一行来解决此问题client.setEndpoint('http://<server_ip>:8088');