簡體   English   中英

如何從PHP調用SoapServer

[英]How to call a SoapServer from PHP

到目前為止,我還無法通過PHP SoapClient將參數成功傳遞到請求中。

<?php

class MockSoapClient extends \SoapClient
{
    public function __doRequest($request, $location, $action, $version, $one_way = 0)
    {
        echo $request.PHP_EOL;

        return '';
    }
}

$client = new MockSoapClient(
    'http://www.saiasecure.com/webservice/shipment/soap.asmx?wsdl',
    [
        'trace' => 1,
        'soap_version' => SOAP_1_1,
    ]
);

$client->__soapCall(
    'GetByProNumber',
    [
        'parameters' => [
            'UserID' => 'username',
            'Password' => 'password',
            'TestMode' => 'Y',
            'ProNumber' => '123',
        ]
    ]
);

運行:php test.php | xmllint -format-

獲取輸出:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.SaiaSecure.com/WebService/Shipment">
  <SOAP-ENV:Body>
    <ns1:GetByProNumber/>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

期望輸出在GetByProNumber元素內包含某種形式的參數。

PHP版本:7.0.30(Ubuntu 16.04)

沒有“錯誤”報告緊密地模仿了這個問題,但是我無法深入了解如何進行更改才能使此工作正常進行。 https://bugs.php.net/bug.php?id=33366

任何人有任何見解或提示嗎?

我剛剛檢查了您的wsdl,看來正確的參數數組應該像這樣:

[
    'parameters' => [
        'request' => [
            'UserID' => 'username',
            'Password' => 'password',
            'TestMode' => 'Y',
            'ProNumber' => '123',
        ]
    ]
]

那么輸出將是這樣的:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.SaiaSecure.com/WebService/Shipment"><SOAP-ENV:Body><ns1:GetByProNumber><ns1:request><ns1:UserID>username</ns1:UserID><ns1:Password>password</ns1:Password><ns1:TestMode>Y</ns1:TestMode><ns1:ProNumber>123</ns1:ProNumber></ns1:request></ns1:GetByProNumber></SOAP-ENV:Body></SOAP-ENV:Envelope>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM