Error: Non-whitespace before first tag but no Byte-Order-Mark in Hex, when calling SOAP service

1.1k views Asked by At

I'm calling a soap service created using Node-Soap, here is the WSDL.

     <?xml version="1.0" encoding="UTF-8"?>
        <definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
                     xmlns:xs="http://www.w3.org/2001/XMLSchema"
                     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                     xmlns:tns="http://www.oorsprong.org/websamples.countryinfo"
                     name="CourseInfoService"
                     targetNamespace="http://www.example.org/websamples.CourseInfoService">
            <types>
                <xs:complexType name="ArrayOftCourses">
                    <xs:sequence>
                        <xs:element name="tCourse" type="tns:tCourse" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
                    </xs:sequence>
                </xs:complexType>


                <xs:element name="ListCoursesRequest">
                    <xs:complexType>
                        <xs:sequence/>
                    </xs:complexType>
                </xs:element>
                <xs:element name="ListCoursesResponse">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="ListCoursesResult" type="tns:ArrayOftCourses"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
    </types>
 <message name="ListCoursesRequest">
        <part name="parameters" element="tns:ListCoursesRequest"/>
    </message>
    <message name="ListCoursesResponse">
        <part name="parameters" element="tns:ListCoursesResponse"/>
    </message>
<portType name="CourseInfoSoapType">
        <operation name="ListCourses">
            <documentation>Returns a list of continents ordered by name.</documentation>
            <input message="tns:ListCoursesRequest"/>
            <output message="tns:SearchCoursesResponse"/>
        </operation>
</portType>
<binding name="CountryInfoServiceSoapBinding" type="tns:CourseInfoSoapType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

        <operation name="ListCourses">
            <soap:operation soapAction="" style="document"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
</binding>
<service name="CourseInfoService">
        <documentation>Stub doc</documentation>
        <port name="CountryInfoServiceSoap" binding="tns:CountryInfoServiceSoapBinding">
            <soap:address location="http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso"/>
        </port>
    </service>
</definitions>

I've inspected in a hex editor for the Byte-Order-Mark and also used .replace('\ufeff', '') on string itself. The code used to create the soap 'route' looks like this:

module.exports = function(app){
    const   soap = require('soap'),
            xml = require('fs').readFileSync('./routes/soapService.wsdl', 'utf8').replace('\ufeff', '');

    const   service = {
        CountryInfoServiceSoapBinding: {
            CourseInfoSoapType: {
                getCourses: function(args) {
                    return {
                        courses: [{
                            name: 'Hello',
                            credits: 123,
                            duration: 24
                        }, {
                            name: 'World',
                            credits: 456,
                            duration: 36
                        },
                    ]};
                },
                searchCourses: function(args) {
                    return {
                        courses: [{
                            name: 'Hello',
                            credits: 123,
                            duration: 24
                        }, {
                            name: 'World',
                            credits: 456,
                            duration: 36
                        }]

                    };
                },
                addCourse: function(args) {
                    return {
                        courses: 'Success!'
                    };
                },
            }
        }
    };

    soap.listen(app, '/wsdl', service, xml);
    console.log('Soap api on: /wsdl');
};

The request for the course data looks like:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pm="http://www.getpostman.com/">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
    <pm:ListCourses>
    </pm:ListCourses>
</soapenv:Body>
</soapenv:Envelope>

And the response that receives is:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:tns="http://www.oorsprong.org/websamples.countryinfo">
    <soap:Header>
        <o:Security soap:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <u:Timestamp u:Id="_0">
                <u:Created>2017-01-06T15:07:48Z</u:Created>
                <u:Expires>2017-01-06T15:17:48Z</u:Expires>
            </u:Timestamp>
        </o:Security>
    </soap:Header>
    <soap:Body>
        <soap:Fault>
            <faultcode>500</faultcode>
            <faultstring>Invalid XML</faultstring>
            <detail>Error: Non-whitespace before first tag.
Line: 0
Column: 1
Char: [</detail>
        </soap:Fault>
    </soap:Body>
</soap:Envelope>

If somebody could point me in right direction that would be great.

1

There are 1 answers

0
Aster On

You should start http server and then connect your soap.listen to it.

 server = http.createServer(app).listen(8888, function(){
        var xml = require('fs').readFileSync('./apis/hello.wsdl', 'utf8');
         soap.listen(server, '/service', soapTest, xml);        
    });

Here app is my express instance.