首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:调用SOAP服务时,第一个标记前没有空格,但十六进制中没有Byte-Order-Mark

错误:调用SOAP服务时,第一个标记前没有空格,但十六进制中没有Byte-Order-Mark
EN

Stack Overflow用户
提问于 2017-01-06 23:10:16
回答 1查看 829关注 0票数 0

我正在调用一个使用Node-Soap创建的soap服务,这里是WSDL。

代码语言:javascript
复制
     <?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', '')。用于创建soap“路由”的代码如下所示:

代码语言:javascript
复制
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');
};

课程数据的请求如下所示:

代码语言:javascript
复制
<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>

收到的响应是:

代码语言:javascript
复制
<?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>

如果有人能给我指出正确的方向,那就太好了。

EN

回答 1

Stack Overflow用户

发布于 2017-05-12 17:11:14

您应该启动http服务器,然后将您的soap.listen连接到它。

代码语言:javascript
复制
 server = http.createServer(app).listen(8888, function(){
        var xml = require('fs').readFileSync('./apis/hello.wsdl', 'utf8');
         soap.listen(server, '/service', soapTest, xml);        
    });

这里的app是我的express实例。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41508516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档