【发布时间】:2014-08-17 08:48:58
【问题描述】:
我使用 PHP 的 XMLWriter 创建了一个 XML 文档。
$xmlWriter = new \XMLWriter();
$xmlWriter->openMemory(); //generate XML in-memory, not on disk
//Please keep the indentation intact to preserve everybody's sanity!
$xmlWriter->startElement('RootElement');
// ...
$xmlWriter->endElement();
$myXml = $xmlWriter->outputMemory(true);
现在我以非 WSDL 模式连接到 SOAP 服务。
$soapClient = new \SoapClient(null, array(
"location" => "https://theservice.com:1234/soap/",
"uri" => "http://www.namespace.com",
"trace" => 1
)
);
$params = array(
new \SoapParam($myXml, 'param')
);
$result = $soapClient->__soapCall('method', $params);
问题是 SOAP 服务接收到的 SOAP 消息包含我的数据作为转义的 XML 字符。 (警告:前面的虚拟 SOAP 消息!)
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope" ...>
<SOAP-ENV:Header>
...
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:method>
<Request xsi:type="xsd:string">
<Root>
(escaped data)
</Root>
</Request>
</ns1:method>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SOAP 服务不能处理转义的数据,但另一方面,我不会转义我的数据,SoapClient 会这样做。如何让我的SoapClient 发送未转义的数据?
【问题讨论】: