user182907
user182907

Reputation: 11

Node SOAP, request gives empty soap body

I am using SOAP npm module to create a SOAP server. Then binding below module to /wsdl endpoint using soap module.

var dns = require('dns');

export default {
    MyService: {
        MyServicePortType: {
            MyFunction: function(args, callback) {
                console.log(args);
                if(!args.domain) {
                    return {
                        ip: 'Please pass a domain name like google.com'
                    }
                }else {
                    dns.lookup(args.domain, function (err, addresses, family) {
                        console.log(addresses, family);
                        callback({
                            ip: addresses
                        });
                    });
                }
            }
        }
    }
};

This is the WSDL I am using

<wsdl:definitions name="MyService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://localhost:3000/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://localhost:3000/wsdl">

   <wsdl:documentation>MyService</wsdl:documentation>

   <wsdl:types>
      <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://localhost:3000/wsdl">
         <xs:element name="IpRequest">
            <xs:complexType>
               <xs:sequence>
                  <xs:element minOccurs="0" name="domain" type="xs:string" />
               </xs:sequence>
            </xs:complexType>
         </xs:element>
         <xs:element name="IpResponse">
            <xs:complexType>
               <xs:sequence>
                  <xs:element minOccurs="0" name="ip" type="xs:string" />
               </xs:sequence>
            </xs:complexType>
         </xs:element>
      </xs:schema>
   </wsdl:types>

   <wsdl:message name="domainRequest">
      <wsdl:part name="parameters" element="ns:IpRequest" />
   </wsdl:message>
   <wsdl:message name="domainResponse">
      <wsdl:part name="parameters" element="ns:IpResponse" />
   </wsdl:message>

   <wsdl:portType name="MyServicePortType">
      <wsdl:operation name="MyFunction">
         <wsdl:input message="ns:domainRequest" />
         <wsdl:output message="ns:domainResponse" />
      </wsdl:operation>
   </wsdl:portType>

   <wsdl:binding name="MyServiceHttpBinding" type="ns:MyServicePortType">
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
      <wsdl:operation name="MyFunction">
         <soap:operation soapAction="http://localhost:3000/wsdl/MyFunction" style="document" />
         <wsdl:input>
            <soap:body use="literal" />
         </wsdl:input>
         <wsdl:output>
            <soap:body use="literal" />
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>

   <wsdl:service name="MyService">
      <wsdl:port name="MyServiceHttpsEndpoint" binding="ns:MyServiceHttpBinding">
         <soap:address location="http://localhost:3000/wsdl" />
      </wsdl:port>
   </wsdl:service>

</wsdl:definitions>

When I make a SOAP request from postman it is giving empty soap body in response,

Request

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://localhost:3000/wsdl">
  <soap:Body>
    <ns:IpRequest>
        <ns:domain>yahoo.com</ns:domain>
    </ns:IpRequest>
  </soap:Body>
</soap:Envelope>

Response

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:ns="http://localhost:3000/wsdl">
    <soap:Body/>
</soap:Envelope>

Console.log statement in MyFunction is also not executing. Is it because something is wrong in WSDL or soap request?

Upvotes: 1

Views: 1202

Answers (1)

user14983387
user14983387

Reputation: 11

From soap client 0.34.0 bluebird promises are replaced by custom promisifying (see https://github.com/vpulim/node-soap/pulls/1125), where in the case of async service method with no parameter you should explicitly set the parameter to {} such that the soap body can be correctly written in the request. In my case this was client.GetProcessListAsync({}). I hope this helps anyone stumbling over the same issue ;)

Upvotes: 1

Related Questions