【问题标题】:When I call one method webservice soap with string xml, and get error当我用字符串 xml 调用一种方法 webservice soap 并得到错误
【发布时间】:2016-12-19 02:33:45
【问题描述】:

当我用字符串 xml 调用一种方法 webservice soap 时,得到以下错误:

<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ServiceControllerwsdl">
    <x:Header/>
    <x:Body>
        <urn:luuPhieuNhap>
            <urn:xml_phieu_nhap><?xml version=\"1.0\" encoding=\"utf-8\"?> 
<CustomerSearch>
    <AuthorID>$authorID</AuthorID>
    <UserID>$userID</UserID>
    <UserPassword>$userPassword</UserPassword>
    <Email>$customerEmail</Email>
</CustomerSearch></urn:xml_phieu_nhap>
            <urn:id_nhan_vien>297</urn:id_nhan_vien>
            <urn:id_kho>1</urn:id_kho>
        </urn:luuPhieuNhap>
    </x:Body>
</x:Envelope>

我得到以下错误:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <SOAP-ENV:Fault>
            <faultcode>SOAP-ENV:Client</faultcode>
            <faultstring>Bad Request</faultstring>
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

但是当我使用文本字符串时,它不会出错:下面:

<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ServiceControllerwsdl">
    <x:Header/>
    <x:Body>
        <urn:luuPhieuNhap>
            <urn:xml_phieu_nhap>fsdfdsfd</urn:xml_phieu_nhap>
            <urn:id_nhan_vien>297</urn:id_nhan_vien>
            <urn:id_kho>1</urn:id_kho>
        </urn:luuPhieuNhap>
    </x:Body>
</x:Envelope>

我得到了很好的结果:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:ServiceControllerwsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:luuPhieuNhapResponse>
            <return xsi:type="xsd:integer">-1</return>
        </ns1:luuPhieuNhapResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

如何解决?我在linux、PHP7.0、yii framework 1.1.16中使用SOAP。

【问题讨论】:

    标签: xml linux web-services soap


    【解决方案1】:

    您需要转义 XML 字符或更改架构以使用 xsd:any

    看到这个https://stackoverflow.com/a/2349082/6371459

    除非服务的架构准确地描述了您尝试发送的 XML,否则您必须使用 XML 转义来使您的 XML 作为字符串通过管道。 而不是 , etc, etc, etc.

    或者,您需要更改架构以使用任何粒子的 XML 架构。

    你也可以使用CDATA(文本不解析)并重新解析服务器上的xml

     <urn:xml_phieu_nhap><![CDATA[xmlmessage]]></urn:xml_phieu_nhap>
    

    【讨论】:

      猜你喜欢
      • 2020-07-15
      • 2016-11-20
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 2022-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多