2017-01-06 3 views
0

Я звоню в службу мыла, созданную с помощью Node-Soap, вот WSDL.Ошибка: без пробелов перед первым тегом, но без байта-ордера-отметки в шестнадцатеричном состоянии при вызове службы SOAP

 <?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> 

Я осмотрены в шестнадцатеричном редакторе для Byte-Order-Mark, а также используется .replace('\ufeff', '') на самой строке. код, используемый для создания мыла «маршрут» выглядит следующим образом:

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'); 
}; 

Запрос на данных курса выглядит следующим образом:

<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> 

И ответ, который получает это:

<?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> 

Если кто-то может указать мне в правильном направлении, это было бы здорово.

ответ

0

Вы должны запустить http-сервер, а затем подключить к нему свой soap.listen.

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

Здесь приложение - мой экспресс-экземпляр.