你好我有一个奇怪的问题,如果我可以这样称呼它...我想弄清楚如何发送"半逃脱" xml字符串作为参数,称为" xml"到Soap Web服务。
我需要生成的模式是这个:
<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<AuthHeader xmlns="https://url.temp/">
<UserName>Test</UserName>
<Password>Test</Password>
</AuthHeader>
</soap:Header>
<soap:Body>
<CreateTerminalSession xmlns="https://url.temp/">
<xml><?xml version="1.0" encoding="utf-16"?>
<Request>
<ServiceLogin>
<ServiceUserName>Test</ServiceUserName>
<ServicePassword>Test</ServicePassword>
<MCSAccountID>1</MCSAccountID>
</ServiceLogin>
<SaleInformation>
<DeviceID>2LK1234</DeviceID>
<Type>Sale</Type>
<Amount>1.00</Amount>
<TipAmount>-1</TipAmount>
<AutoTransmit>1</AutoTransmit>
<GatewayID>1</GatewayID>
</SaleInformation>
</Request></xml>
</CreateTerminalSession>
</soap:Body>
</soap:Envelope>
我使用此代码生成的架构是
"""
<?xml version="1.0" encoding="UTF-8"?>\n
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https:/url.temp/"><SOAP-ENV:Header><ns1:AuthHeader><ns1:UserN ▶
&lt;Request&gt;\n
&lt;ServiceLogin&gt;\n
&lt;ServiceUserName&gt;userxxx&lt;/ServiceUserName&gt;\n
&lt;ServicePassword&gt;xxx&lt;/ServicePassword&gt;\n
&lt;MSCSAccountID&gt;xxx8&lt;/MSCSAccountID&gt;\n
&lt;/ServiceLogin&gt;\n
&lt;SaleInformation&gt;\n
&lt;DeviceID&gt;2LK1234&lt;/DeviceID&gt;\n
&lt;Type&gt;Sale&lt;/Type&gt;\n
&lt;Amount&gt;1.00&lt;/Amount&gt;\n
&lt;TipAmount&gt;-1&lt;/TipAmount&gt;\n
&lt;AutoTransmit&gt;1&lt;/AutoTransmit&gt;\n
&lt;GatewayID&gt;1&lt;/GatewayID&gt;\n
&lt;/SaleInformation&gt;\n
&lt;/Request&gt;\n
</ns1:xml></ns1:CreateTerminalSession></SOAP-ENV:Body></SOAP-ENV:Envelope>\n
"""
用于生成上述响应的代码:
$response = $client->__soapCall('CreateTerminalSession', [['xml' => $correctString]]);
这里的错误是XmlWriter逃脱&#34;&amp;&#34;使用&amp; amp在我的情况下无效,webservice拒绝这种格式...
我尝试的解决方案是:
$params = array(
new \SoapParam(new \SoapVar($correctString, XSD_ANYXML), 'xml')
);
$response = $client->__soapCall('CreateTerminalSession', $params);
导致了这种反应。字符串在webservice期望的情况下被正确转义,但是没有命令名称&#34; CreateTerminalSession&#34;既不是param name&#34;&#34;:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://temp.url/">
<SOAP-ENV:Header>
<ns1:AuthHeader>
<ns1:UserName>testurs</ns1:UserName>
<ns1:Password>testww</ns1:Password>
</ns1:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body><?xml version="1.0" encoding="UTF-8"?>
<Request>
<ServiceLogin>
<ServiceUserName>paramservice</ServiceUserName>
<ServicePassword>parampass</ServicePassword>
<MSCSAccountID>paramsscsa</MSCSAccountID>
</ServiceLogin>
<SaleInformation>
<DeviceID>2LK1234</DeviceID>
<Type>Sale</Type>
<Amount>1.00</Amount>
<TipAmount>-1</TipAmount>
<AutoTransmit>1</AutoTransmit>
<GatewayID>1</GatewayID>
</SaleInformation>
</Request>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
导致服务器出现此错误
Server was unable to process request. ---> Value cannot be null.\n
Parameter name: s
所以我的问题是如何使这个正确转义的主体在我的情况下具有命令名称和参数名称&#34; CreateTerminalSession&#34;和&#34; xml&#34;。任何帮助都会非常感激。提前致谢