【发布时间】:2015-06-08 21:34:00
【问题描述】:
我用 C# 编写了一个 WCF Soap 服务,它接受 XML 并对其进行解析以获取字段的值。 我需要在 PHP 中调用此服务。但是我在 PHP 中尝试的代码没有通过 XML,当我在我的服务中调试时 dto.xml 是空的。
这样称呼它:
$wsdl = "http://localhost:525845/cust.svc?wsdl";
$soap_client = new SoapClient($wsdl);
$Process = "LOAD";
$client->soap_defencoding = 'UTF-8';
$xml = new SimpleXMLElement("<Credit></Credit>");
$xml->addChild('LoanApp', $LoanApp);
$xml->addChild('Routing', $Routing);
$xml->addChild('Processing', $Processing);
$xml->addChild('Process', $Process);
$param = array(
'dto' => $xml
);
$result1 = $soap_client->Process_Load($param);
print_r($result1);
这是我的方法是我正在调用的服务:
public string Process_Load(Model.TransferData dto)
{
XmlDocument parsed_xml = new XmlDocument();
string _byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
if (dto.xml.StartsWith(_byteOrderMarkUtf8))
{
dto.xml = dto.xml.Remove(0, _byteOrderMarkUtf8.Length);
}
parsed_xml.LoadXml(dto.xml);
XmlNodeList xnList = parsed_xml.SelectNodes("/IEZ/Credit/LoanApp/Routing/Processing/Process");
if (xnList != null)
Process = xnList.Item(0).InnerText;
这是我从 PHP 传递给服务的 XML 示例:
<IEZ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Credit>
<LoanApp>
<Routing Transaction="LoanApp">
<Processing>
<Process Type="Trans-type">LOAD</Process>
</Processing>
</Routing>
</LoanApp>
【问题讨论】:
-
$xml->addChild('<LoanApp', $LoanApp);中有一个 addChild 时,实体不会被转义。 -
@TomasoAlbinoni 谢谢抱歉,这是我的错误,但在我的代码中没问题。