gpt4 book ai didi

javascript - Node-soap 客户端-服务器测试

转载 作者:行者123 更新时间:2023-12-01 03:56:10 25 4
gpt4 key购买 nike

我需要创建一个 Soap 服务器,但仅用于测试目的。我的 SOAP 客户端与真正的 SOAP 服务一起使用,但不与我的 SOAP 服务一起使用。index.js 和 server.js 位于同一文件夹级别。

wsdl:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://corpwsdl.oneninetwo" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://corpwsdl.oneninetwo" xmlns:intf="http://corpwsdl.oneninetwo" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://rpc.xml.coldfusion" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema targetNamespace="http://rpc.xml.coldfusion" xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="CFCInvocationException">
<sequence/>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="CFCInvocationException">
<wsdl:part name="fault" type="tns1:CFCInvocationException"/>
</wsdl:message>
<wsdl:message name="searchResponse">
<wsdl:part name="searchReturn" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="searchRequest">
<wsdl:part name="xml" type="xsd:string"/>
</wsdl:message>
<wsdl:portType name="IDSearch">
<wsdl:operation name="search" parameterOrder="xml">
<wsdl:input message="impl:searchRequest" name="searchRequest"/>
<wsdl:output message="impl:searchResponse" name="searchResponse"/>
<wsdl:fault message="impl:CFCInvocationException" name="CFCInvocationException"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="IDSearch.cfcSoapBinding" type="impl:IDSearch">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="search">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="searchRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://corpwsdl.oneninetwo" use="encoded"/>
</wsdl:input>
<wsdl:output name="searchResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://corpwsdl.oneninetwo" use="encoded"/>
</wsdl:output>
<wsdl:fault name="CFCInvocationException">
<wsdlsoap:fault encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" name="CFCInvocationException" namespace="http://corpwsdl.oneninetwo" use="encoded"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="IDSearch">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
Main ID Search Web Service </wsdl:documentation>
<wsdl:port binding="impl:IDSearch.cfcSoapBinding" name="IDSearch.cfc">
<wsdlsoap:address location="http://localhost:8001/exp?wsdl"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

与客户的索引:

var url = 'http://localhost:8001/exp';

var options = {
disableCache: true,
escapeXML: true,
envelopeKey: 'SOAP-ENV'
};

var args = {
xml: '<![CDATA['+xml+']]>'
//xml : '<test>hello</test>'
};

soap.createClient(url, options, function (err, client) {
client.search(args, function (err, result, body) {
if (err) {
console.log("error: ", err);
console.log("Last request: \n", client.lastRequest + "\n");
}

var parsingOptions = {
'object': true,
'sanitize': false
};
console.log("Response \n\n", body);

//var jsonResult = parser.toJson(body, parsingOptions);
//console.log(jsonResult['soapenv:Envelope']['soapenv:Body']['ns1:searchResponse']['searchReturn']['$t']);
});
});

服务器.js

var soap = require('soap');
var http = require('http');
var fs = require('fs');
var express = require('express');
var bp = require('body-parser');
var xmlParser = require('xml');
var app = express();

////app.use(bp.json());

console.log("Starting 192com SOAP service");

var myService = {
IDSearch : { // wsdl:service
IDSearch : { // wsdl:port
search: function (args) {
return {
status: "good"
};

}
}
}
}


var xml = require('fs').readFileSync('test/192com/192com.wsdl', 'utf8');

//body parser middleware are supported (optional)
app.use(bp.raw({type: function(){return true;}, limit: '20mb'}));
app.listen(8001, function(){
//Note: /wsdl route will be handled by soap module
//and all other routes & middleware will continue to work
soap.listen(app, '/wsdl', myService, xml);
});

app.get('/exp', function (req, res) {
res.set('Content-Type', 'text/xml');
res.send(xml);
});

当我访问 localhost:8001/exp 时,我得到 WSDL

当我执行 SOAP 客户端时,我得到以下响应:

error:  { Fault: 
{ faultcode: 500,
faultstring: 'Invalid XML',
detail: 'Error: Unexpected close tag\nLine: 5\nColumn: 7\nChar: >',
statusCode: 500 },
response:

回应

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /exp</pre>
</body>

有人知道我的 server.js 或 wsdl 有什么问题吗?

最佳答案

您的 SOAP 服务器需要监听“/exp”路由,而不是“/wsdl”路由,并且您的express应用程序不应使用app.get()处理“/exp”路由。

然后,soap 服务器将自动处理路由“/exp?wsdl”,以提供 wsdl 信息作为对客户端 get 请求的响应。之后,您的客户端将发布请求,该请求将根据 xml 文件内的配置以及提供给soap.listen 函数的服务进行处理。

关于javascript - Node-soap 客户端-服务器测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42652731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com