当我使用字符串XML调用一种方法Web服务肥皂时,并获取错误



用字符串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>

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

<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框架1.1.16。

中使用肥皂

您需要逃脱XML字符或更改模式以使用xsd:any

请参阅此https://stackoverflow.com/a/2349082/6371459

,除非服务的架构准确地描述了您要发送的XML,否则您必须使用XML Escapes将XML通过管道作为字符串通过管道。&lt; tag&gt;而不是等,等等,等等。

或,您需要更改模式以使用XML模式任何粒子。

您也可以使用CDATA(未解析文本),然后在服务器上重新使用XML

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

最新更新