【发布时间】:2020-07-20 20:18:18
【问题描述】:
我正在使用 Express 制作一个包含 API REST 和 SOAP 方法(我使用 https://www.npmjs.com/package/soap)的 NodeJS Web 服务。使用 API REST 我没有任何问题,但使用 SOAP 我有一个不便,当我尝试从测试 C# 应用程序中使用 SOAP 方法时,我可以看到参数运行良好,但在响应中我有下一个错误在 C# 中(响应不是正确的 XML 代码)
当我使用 node-soap 从 NodeJS 客户端使用该方法时,响应工作正常。
我的部分 NodeJS 代码:
const express = require('express');
const bodyParser = require('body-parser');
const soap = require('soap');
const fs = require('fs');
const xml = fs.readFileSync('src/templates/ws_soap.wsdl', 'utf8');
const app = express();
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
const soap_service = {
integrations: {
pull: {
getSnapshotGIGA: function(args) {
return {
res: "HOLA"
};
},
}
}
};
app.listen(port, ip, function() {
soap.listen(app, '/integrations_service', soap_service, xml, function() {
console.log('SOAP web service started on ' + ip + ':' + port);
});
console.log('API REST started on ' + ip + ':' + port);
});
接下来是我的 WSDL 文件(作为响应,我有类型字符串,因为我想看看它的行为方式,但我需要返回一个对象 XML):
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="integrations_service" targetNamespace="http://localhost:4205/integrations_service" xmlns="http://localhost:4205/integrations_service" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<wsdl:message name="getSnapshotGIGARequest">
<wsdl:part name="User" type="xs:string"/>
<wsdl:part name="Password" type="xs:string"/>
</wsdl:message>
<wsdl:message name="getSnapshotGIGAResponse">
<wsdl:part name="res" type="xs:string"/>
</wsdl:message>
<wsdl:portType name="pull_integrations">
<wsdl:operation name="getSnapshotGIGA">
<wsdl:input message="getSnapshotGIGARequest"/>
<wsdl:output message="getSnapshotGIGAResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="pull_integrations_binding" type="pull_integrations">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getSnapshotGIGA">
<soap:operation soapAction="getSnapshotGIGA"/>
<wsdl:input>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="integrations">
<wsdl:port binding="pull_integrations_binding" name="pull">
<soap:address location="http://localhost:4205/integrations_service"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
在 C# 中,我有一个控制台应用程序,并且我已将 SOAP 服务注册为 Web 引用。
我使用 SOAP 方法的方式是(当我使用 C# 制作 SOAP 服务时,我也会通过这种方式测试方法,因为这是客户端工作的方式):
Console.WriteLine("Consume NodeJS SOAP service");
Thread.Sleep(500);
integrations_service.integrations integrations = new integrations_service.integrations();
integrations.Url = "http://localhost:4205/integrations_service?wsdl";
var some_response = integrations.getSnapshotGIGA("myuser", "123456");
Console.WriteLine("Press enter to out...");
我想像这个例子一样在 XmlNode 中获得响应:
Console.WriteLine("Consume C# SOAP service");
Thread.Sleep(500);
serviceSOAP sSOAP = new serviceSOAP ();
sSOAP.Url = "http://my.domain.com.mx/";
XmlNode xmlNode = sSOAP .anyMethodSoap("yomero", "123456");
Console.WriteLine(XElement.Parse(xmlNode.OuterXml).ToString());
Thread.Sleep(500);
如果您知道如何从 NodeJS 返回 XML 并在 C# 或任何想法中正确获取它,我将不胜感激。问候。
【问题讨论】:
标签: c# node.js soap soap-client node-soap