PHP soapClient 多次调用失败

PHP soapClient multiple calls fail

我必须在 while 循环中调用 Web 服务以从数据库提交多条记录。 问题是只有第一条记录是后置的。 似乎 webservice 调用终止了 while 循环并且不再获取其他记录。 网络服务调用本身是正确的。 有人可以帮助我吗?

代码如下:

error_reporting(E_ALL ^ E_NOTICE);
include("include/dbConn.php");

$client = new SoapClient("myservice.asmx?wsdl",array(
                        'exceptions'=>true,
                        'cache_wsdl'=>WSDL_CACHE_NONE,
                        'features' =>SOAP_WAIT_ONE_WAY_CALLS,
                        'encoding'=>'utf-8'));

$Context =array(
        "B1DBName" => "TestDB",
        "B1DefaultPriceListNumber" => "1",
        "B1UKStandardVatCode" => "O1",
);


$strSql="select * from custom_clients_insert_view";
$result = mysqli_query($conn,$strSql) or die("MySQL error: " . mysqli_error($conn) . "<hr>\nQuery: $strSql");  
while($row = mysqli_fetch_array($result)) 
{
    $Cust =array(
        "CardCode" => "",
        "WebPassword" => "",
        "EmailAddress" => $row['email'],
        "Title" => "",
        "FirstName" => $row['b_firstname'],
        "Surname" => $row['b_lastname'],
        "Telephone" => $row['b_phone'],
        "WebID" => $row['user_id'],
        "VATNumber" => "",
        "FaxNumber" => $row['fax'],
        "Telephone2" => "",
        "Organisation" => "",
        "MobilePhone" => ""
    );

    $params = array(
    'Context' => $Context,
    'WebsiteName' => "test2",
    'Cust' => $Cust,
    'ActiveCust' => true
    );

    try 
    {
        $result = $client->SubmitNewCustomerToB1($params);
        var_dump($result);
        echo "<br><br> VALUE:" . $result->SubmitNewCustomerToB1Result;
        /* do something on my log */
    } 
    catch (Exception $e) 
    {
        echo "Error!<br />";
        echo $e -> getMessage ();
        var_dump($result);
        echo "<br><br> VALUE:" . $result->SubmitNewCustomerToB1Result;
        /* do something on my log*/
    }

}

解决方案是将记录集放入数组中,然后使用 for each 语句在数组上循环。

这是工作代码:

include("include/dbConn.php");

$CustArray = array();

$client = new SoapClient("WSDL EDNPOINT HERE",array(
                        'exceptions'=>true,
                        'cache_wsdl'=>WSDL_CACHE_NONE,
                        'encoding'=>'utf-8'));

$strSql="SELECT * FROM custom_clients_insert_view";
$result = mysqli_query($conn,$strSql) or die("MySQL error: " . mysqli_error($conn) . "<hr>\nQuery: $strSql");  
while($row = mysqli_fetch_array($result)) 
{

    $Context =array(
        "B1DBName" => "TESTDB",
        "B1DefaultPriceListNumber" => "1",
        "B1UKStandardVatCode" => "O1",
    );


    $WebsiteName =array(
        "WebsiteName"=> "Test webiste"
    );

    $ActiveCust =array(
            "ActiveCust" => "true"
    );


    $Cust =array(
        "CardCode" => "",
        "WebPassword" => "",
        "EmailAddress" => $row['email'],
        "Title" => "",
        "FirstName" => $row['b_firstname'],
        "Surname" => $row['b_lastname'],
        "Telephone" => $row['b_phone'],
        "WebID" => $row['user_id'],
        "VATNumber" => "",
        "FaxNumber" => $row['fax'],
        "Telephone2" => "",
        "Organisation" => "",
        "MobilePhone" => ""
    );

    $params = array(
    'Context' => $Context,
    'WebsiteName' => $WebsiteName,
    'Cust' => $Cust,
    'ActiveCust' => $ActiveCust
    );

    array_push($CustArray, $params);
}

foreach ($CustArray as $params) 
{
    try 
    {
        $result = $client->SubmitNewCustomerToB1($params);
        var_dump($result);
        echo "<br><br> VALUE:" . $result->SubmitNewCustomerToB1Result;
    } 
    catch (Exception $e) 
    {
        echo "Error!<br />";
        echo $e -> getMessage ();
        var_dump($result);
        echo "<br><br> VALUE:" . $result->SubmitNewCustomerToB1Result;
    }
}