title: How to use Cloud Functions for Firebase to write a SOAP service?
body: <p>I need to implement an soap web service using firebase functions.
  I found a module called soap-node <a href="https://github.com/vpulim/node-soap" rel="noreferrer">soap-module-github</a> which seems promising, since it integrates with express, and firebase says it uses express for http calls, but the problem, is I don't know how to integrate that module with firebase functions since, firebase functions are the handler of the http calls made by the clients, any help would be very helpfull.</p>
  
  <p>Here is the code I have managed to create so far:</p>
  
  <pre><code>    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 &gt; 0 &amp;&amp; price &lt; 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);
  </code></pre>
  
  <p>here is the stockquote.wsdl:
      </p>
  
  <pre><code>&lt;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/"&gt;
  
  &lt;wsdl:types&gt;
     &lt;xsd:schema targetNamespace="http://example.com/stockquote.xsd" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"&gt;
         &lt;xsd:element name="TradePriceRequest"&gt;
            &lt;xsd:complexType&gt;
                &lt;xsd:all&gt;
                    &lt;xsd:element name="tickerSymbol" type="string"/&gt;
                &lt;/xsd:all&gt;
            &lt;/xsd:complexType&gt;
         &lt;/xsd:element&gt;
         &lt;xsd:element name="TradePrice"&gt;
            &lt;xsd:complexType&gt;
                &lt;xsd:all&gt;
                    &lt;xsd:element name="price" type="float"/&gt;
                &lt;/xsd:all&gt;
            &lt;/xsd:complexType&gt;
         &lt;/xsd:element&gt;
         &lt;xsd:element name="TradePriceSubmit"&gt;
             &lt;xsd:complexType&gt;
                 &lt;xsd:all&gt;
                     &lt;xsd:element name="tickerSymbol" type="string"/&gt;
                     &lt;xsd:element name="price" type="float"/&gt;
                 &lt;/xsd:all&gt;
             &lt;/xsd:complexType&gt;
         &lt;/xsd:element&gt;
         &lt;xsd:element name="valid" type="boolean"/&gt;
     &lt;/xsd:schema&gt;
  &lt;/wsdl:types&gt;
  
  &lt;wsdl:message name="GetLastTradePriceInput"&gt;
      &lt;wsdl:part name="body" element="xsd1:TradePriceRequest"/&gt;
  &lt;/wsdl:message&gt;
  
  &lt;wsdl:message name="GetLastTradePriceOutput"&gt;
      &lt;wsdl:part name="body" element="xsd1:TradePrice"/&gt;
  &lt;/wsdl:message&gt;
  
  &lt;wsdl:message name="SetTradePriceInput"&gt;
      &lt;wsdl:part name="body" element="xsd1:TradePriceSubmit"/&gt;
  &lt;/wsdl:message&gt;
  
  &lt;wsdl:message name="IsValidPriceInput"&gt;
      &lt;wsdl:part name="body" element="xsd1:TradePrice"/&gt;
  &lt;/wsdl:message&gt;
  
  &lt;wsdl:message name="IsValidPriceOutput"&gt;
      &lt;wsdl:part name="body" element="xsd1:valid"/&gt;
  &lt;/wsdl:message&gt;
  
  &lt;wsdl:portType name="StockQuotePortType"&gt;
      &lt;wsdl:operation name="GetLastTradePrice"&gt;
         &lt;wsdl:input message="tns:GetLastTradePriceInput"/&gt;
         &lt;wsdl:output message="tns:GetLastTradePriceOutput"/&gt;
      &lt;/wsdl:operation&gt;
      &lt;wsdl:operation name="SetTradePrice"&gt;
          &lt;wsdl:input message="tns:SetTradePriceInput"/&gt;
      &lt;/wsdl:operation&gt;
      &lt;wsdl:operation name="IsValidPrice"&gt;
          &lt;wsdl:input message="tns:IsValidPriceInput"/&gt;
          &lt;wsdl:output message="tns:IsValidPriceOutput"/&gt;
      &lt;/wsdl:operation&gt;
  &lt;/wsdl:portType&gt;
  
  &lt;wsdl:binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType"&gt;
      &lt;soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/&gt;
      &lt;wsdl:operation name="GetLastTradePrice"&gt;
         &lt;soap:operation soapAction="http://example.com/GetLastTradePrice"/&gt;
         &lt;wsdl:input&gt;
             &lt;soap:body use="literal"/&gt;
         &lt;/wsdl:input&gt;
         &lt;wsdl:output&gt;
             &lt;soap:body use="literal"/&gt;
         &lt;/wsdl:output&gt;
      &lt;/wsdl:operation&gt;
      &lt;wsdl:operation name="SetTradePrice"&gt;
          &lt;soap:operation soapAction="http://example.com/SetTradePrice"/&gt;
          &lt;wsdl:input&gt;
              &lt;soap:body use="literal"/&gt;
          &lt;/wsdl:input&gt;
      &lt;/wsdl:operation&gt;
      &lt;wsdl:operation name="IsValidPrice"&gt;
          &lt;soap:operation soapAction="http://example.com/IsValidPrice"/&gt;
          &lt;wsdl:input&gt;
              &lt;soap:body use="literal"/&gt;
          &lt;/wsdl:input&gt;
      &lt;/wsdl:operation&gt;
  &lt;/wsdl:binding&gt;
  
  &lt;wsdl:service name="StockQuoteService"&gt;
      &lt;wsdl:port name="StockQuotePort" binding="tns:StockQuoteSoapBinding"&gt;
         &lt;soap:address location="http://localhost:5002/stockquote"/&gt;
      &lt;/wsdl:port&gt;
  &lt;/wsdl:service&gt;
  </code></pre>
  
  <p>
  I have googled very good I just don't find some path , I also searched google functions and their integration with soap, since firebase functions are just google cloud functions used for firebase</p>