gpt4 book ai didi

web-services - 如何使用 Cloud Functions for Firebase 编写 SOAP 服务?

转载 作者:行者123 更新时间:2023-12-05 00:50:57 25 4
gpt4 key购买 nike

我需要使用 firebase 函数实现一个 SOAP 网络服务。
我找到了一个名为soap-node soap-module-github的模块这似乎很有希望,因为它与 express 集成,并且 firebase 说它使用 express 进行 http 调用,但问题是我不知道如何将该模块与 firebase 函数集成,因为 firebase 函数是进行 http 调用的处理程序客户的任何帮助都会非常有帮助。

这是到目前为止我设法创建的代码:

    var fs = require('fs'),
soap = require('soap'),
express = require('express'),
lastReqAddress;
var server = express();
service = {
StockQuoteService: {
StockQuotePort: {
GetLastTradePrice: function (args, cb, soapHeader) {
if (soapHeader)
return {
price: soapHeader.SomeToken
};
if (args.tickerSymbol === 'trigger error') {
throw new Error('triggered server error');
} else if (args.tickerSymbol === 'Async') {
return cb({
price: 19.56
});
} else if (args.tickerSymbol === 'SOAP Fault v1.2') {
throw {
Fault: {
Code: {
Value: "soap:Sender",
Subcode: {
value: "rpc:BadArguments"
}
},
Reason: {
Text: "Processing Error"
}
}
};
} else if (args.tickerSymbol === 'SOAP Fault v1.1') {
throw {
Fault: {
faultcode: "soap:Client.BadArguments",
faultstring: "Error while processing arguments"
}
};
} else {
return {
price: 19.56
};
}
},

SetTradePrice: function (args, cb, soapHeader) {},

IsValidPrice: function (args, cb, soapHeader, req) {
lastReqAddress = req.connection.remoteAddress;

var validationError = {
Fault: {
Code: {
Value: "soap:Sender",
Subcode: {
value: "rpc:BadArguments"
}
},
Reason: {
Text: "Processing Error"
},
statusCode: 500
}
};

var isValidPrice = function () {
var price = args.price;
if (isNaN(price) || (price === ' ')) {
return cb(validationError);
}

price = parseInt(price, 10);
var validPrice = (price > 0 && price < Math.pow(10, 5));
return cb(null, {
valid: validPrice
});
};

setTimeout(isValidPrice, 10);
}
}
}
};
var wsdl = fs.readFileSync(__dirname + '/../wsdl/stockquote.wsdl', 'utf-8').toString();
server = express();

soapServer = soap.listen(server, '/stockquote', service, wsdl);

这是 stockquote.wsdl:

<wsdl:definitions name="StockQuote"
targetNamespace="http://example.com/stockquote.wsdl"
xmlns:tns="http://example.com/stockquote.wsdl"
xmlns:xsd1="http://example.com/stockquote.xsd"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

<wsdl:types>
<xsd:schema targetNamespace="http://example.com/stockquote.xsd" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema">
<xsd:element name="TradePriceRequest">
<xsd:complexType>
<xsd:all>
<xsd:element name="tickerSymbol" type="string"/>
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="TradePrice">
<xsd:complexType>
<xsd:all>
<xsd:element name="price" type="float"/>
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="TradePriceSubmit">
<xsd:complexType>
<xsd:all>
<xsd:element name="tickerSymbol" type="string"/>
<xsd:element name="price" type="float"/>
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="valid" type="boolean"/>
</xsd:schema>
</wsdl:types>

<wsdl:message name="GetLastTradePriceInput">
<wsdl:part name="body" element="xsd1:TradePriceRequest"/>
</wsdl:message>

<wsdl:message name="GetLastTradePriceOutput">
<wsdl:part name="body" element="xsd1:TradePrice"/>
</wsdl:message>

<wsdl:message name="SetTradePriceInput">
<wsdl:part name="body" element="xsd1:TradePriceSubmit"/>
</wsdl:message>

<wsdl:message name="IsValidPriceInput">
<wsdl:part name="body" element="xsd1:TradePrice"/>
</wsdl:message>

<wsdl:message name="IsValidPriceOutput">
<wsdl:part name="body" element="xsd1:valid"/>
</wsdl:message>

<wsdl:portType name="StockQuotePortType">
<wsdl:operation name="GetLastTradePrice">
<wsdl:input message="tns:GetLastTradePriceInput"/>
<wsdl:output message="tns:GetLastTradePriceOutput"/>
</wsdl:operation>
<wsdl:operation name="SetTradePrice">
<wsdl:input message="tns:SetTradePriceInput"/>
</wsdl:operation>
<wsdl:operation name="IsValidPrice">
<wsdl:input message="tns:IsValidPriceInput"/>
<wsdl:output message="tns:IsValidPriceOutput"/>
</wsdl:operation>
</wsdl:portType>

<wsdl:binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetLastTradePrice">
<soap:operation soapAction="http://example.com/GetLastTradePrice"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="SetTradePrice">
<soap:operation soapAction="http://example.com/SetTradePrice"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="IsValidPrice">
<soap:operation soapAction="http://example.com/IsValidPrice"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
</wsdl:binding>

<wsdl:service name="StockQuoteService">
<wsdl:port name="StockQuotePort" binding="tns:StockQuoteSoapBinding">
<soap:address location="http://localhost:5002/stockquote"/>
</wsdl:port>
</wsdl:service>

我用谷歌搜索得很好我只是没有找到一些路径,我还搜索了谷歌函数及其与soap的集成,因为firebase函数只是用于firebase的谷歌云函数

最佳答案

查看 node-soap 的源代码,你应该可以直接通过_requestListener到云函数的onRequest功能:

exports.stockquote = functions.https.onRequest(soapServer._requestListener)

关于web-services - 如何使用 Cloud Functions for Firebase 编写 SOAP 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45033010/

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