尝试使用 PHP 5.x 查询托管在 IIS 服务器上的 .NET Web 服务
$wsdl_path = "http://192.168.1.1/TestSite/TestService.asmx?wsdl";
$soapClient = new SoapClient($wsdl_path, array('trace' => 1));
$dump=var_export($soapClient->__getFunctions(), true);
echo htmlentities($dump);
produces
array (
0 => 'ProcessTransactionResponse ProcessTransaction(ProcessTransaction $parameters)',
1 => 'ProcessTransactionResponse ProcessTransaction(ProcessTransaction $parameters)',
)
这表明它正在正确访问 wsdl 文件。
使用 SoapUI 验证的格式正确的查询如下
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.mydomain.tld/">
<soapenv:Header/>
<soapenv:Body>
<ws:ProcessTransaction>
<!--Optional:-->
<ws:request>
<!--Optional:-->
<ws:Header>
<!--Optional:-->
<ws:Token>hello</ws:Token>
</ws:Header>
<!--Optional:-->
<ws:Parameters>
<ws:DeviceID>12345</ws:DeviceID>
<ws:SourceScreen>12345</ws:SourceScreen>
<!--Optional:-->
<ws:Language>E</ws:Language>
<ws:LocalDateTime>2015-05-20T11:59:29.910Z</ws:LocalDateTime>
<ws:TicketID>12345</ws:TicketID>
<ws:PayScreenAttributeID>12345</ws:PayScreenAttributeID>
<!--Optional:-->
<ws:InputValue>1234556789</ws:InputValue>
<ws:PaymentAmount>0</ws:PaymentAmount>
<!--Optional:-->
<ws:POSReceiptCustomer>?</ws:POSReceiptCustomer>
<!--Optional:-->
<ws:POSReceiptMerchant>?</ws:POSReceiptMerchant>
</ws:Parameters>
</ws:request>
</ws:ProcessTransaction>
</soapenv:Body>
</soapenv:Envelope>
因此,为了使用 PHP 和 SoapClient 复制此内容,我收集了数组中的数据元素
$inputParams=array(
'Token' => 'hello',
'DeviceID' => 12345,
'SourceScreen' => 12345,
'Language' => 'E',
'LocalDateTime' => '2015-05-20T11:59:29.910Z',
'TicketID' => 12345,
'PayScreenAttributeID' => 12345,
'InputValue' => '123456789',
'PaymentAmount' => 0,
'POSReceiptCustomer' => '?',
'POSReceiptMerchant' => '?',
);
并执行查询
try {
$response = $soapClient->__soapCall('ProcessTransaction', array('parameters' => $inputParams));
var_dump($response);
} catch (SoapFault $fault) {
var_dump($fault);
echo "SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})";
echo "REQUEST:\n" . htmlentities($soapClient->__getLastRequest()) . "\n";
}
我得到了可怕的Server was unable to process request. ---> Object reference not set to an instance of an object.
这不是很有用。
当我看着__getLastRequest()
输出,它似乎显示了包装器,但没有显示任何查询元素
REQUEST:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.mydomain.tld/"><SOAP-ENV:Body><ns1:ProcessTransaction/></SOAP-ENV:Body></SOAP-ENV:Envelope>
我尝试过使用和不使用 Token 元素都无济于事,并且最初遗漏了可选字段(在 SoapUI 界面中工作正常),但也没有任何乐趣。
我怀疑它与带有 Token 元素的附加标头容器有关,因为我们的其他肥皂实现未包含此元素。