PHP soap issue 複雜類型:SOAP-ERROR: Encoding: object 沒有 property


Php soap issue complex type : SOAP-ERROR: Encoding: object has no propertyobject

我必须使用 PHP 调用 .net Web 服务。对于对 Web 服务的单个调用,一切都很好。当我尝试发送多条记录时,出现错误:

SOAP-ERROR: 编码: 对象没有 'ActiveCust' 属性对象(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(21) ["lengths"]=> NULL ["num_rows"]=> int(

2) ["type"]=> int(0) }

这是 wsdl:

<s:element name="SubmitNewCustomerToB1">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="Context" type="tns:B1Context"/>
            <s:element minOccurs="0" maxOccurs="1" name="WebsiteName" type="s:string"/>
            <s:element minOccurs="0" maxOccurs="1" name="Cust" type="tns:Customer"/>
            <s:element minOccurs="1" maxOccurs="1" name="ActiveCust" type="s:boolean"/>
            <s:element minOccurs="0" maxOccurs="1" name="CustomerCustomAttrs" type="tns:ArrayOfCustomAttribute"/>
        </s:sequence>
    </s:complexType>
</s:element>
<s:element name="SubmitNewCustomerToB1Response">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="SubmitNewCustomerToB1Result" type="s:int"/>
        </s:sequence>
    </s:complexType>
</s:element>

以下是适用于单个客户的代码:

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

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

$Cust =array(
    "CardCode" => "",
    "WebPassword" => "",
    "EmailAddress" => "l@l.com",
    "Title" => "Mr",
    "FirstName" => "Alexander",
    "Surname" => "Calder",
    "Telephone" => "02094388",
    "WebID" => "1990",
    "VATNumber" => "",
    "FaxNumber" => "0209998",
    "Telephone2" => "",
    "Organisation" => "",
    "MobilePhone" => ""
);

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

//Parameters must be an associative array
$params = array(
    'Context' => $Context,
    'WebsiteName' => $WebsiteName,
    'Cust' => $Cust,
    'ActiveCust' => $ActiveCust
);
var_dump($params);
try 
{
    $client = new SoapClient("http://theipaddress/b1synccontext.asmx?wsdl");
    $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;
}

在这里,我用来向Web服务提交多个客户的代码

include("include/dbConn.php");
$CustArray = array();
$Context =array(
        "B1DBName" => "TestDB",
        "B1DefaultPriceListNumber" => "1",
        "B1UKStandardVatCode" => "O1",
);

$WebsiteName =array(
    "WebsiteName"=> "Test webiste"
);
$ActiveCust =array(
        "ActiveCust" => "true"
);
$strSql="SELECT * FROM custom_clients_insert_view where b_lastname in('Hawkins','James')";
$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' => $WebsiteName,
    'Cust' => $Cust,
    'ActiveCust' => $ActiveCust
    );
    /*here I create the sequence by pushing the $params array in the parent array $CustArray*/
    array_push($CustArray, $params);
}
var_dump($CustArray);
try 
{
    $client = new SoapClient("http://ipaddress/b1synccontext.asmx?wsdl");
    $result = $client->SubmitNewCustomerToB1($CustArray);
    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;
}

这是我提交的数组

array(2) {
  [0]=>
  array(4) {
    ["Context"]=>
    array(3) {
      ["B1DBName"]=>
      string(11) "SGL_WebTest"
      ["B1DefaultPriceListNumber"]=>
      string(1) "1"
      ["B1UKStandardVatCode"]=>
      string(2) "O1"
    }
    ["WebsiteName"]=>
    array(1) {
      ["WebsiteName"]=>
      string(12) "Test webiste"
    }
    ["Cust"]=>
    array(13) {
      ["CardCode"]=>
      string(0) ""
      ["WebPassword"]=>
      string(0) ""
      ["EmailAddress"]=>
      string(13) "mel@mel.co.uk"
      ["Title"]=>
      string(0) ""
      ["FirstName"]=>
      string(7) "Melanie"
      ["Surname"]=>
      string(7) "Hawkins"
      ["Telephone"]=>
      string(13) "020 477448844"
      ["WebID"]=>
      string(5) "28881"
      ["VATNumber"]=>
      string(0) ""
      ["FaxNumber"]=>
      string(0) ""
      ["Telephone2"]=>
      string(0) ""
      ["Organisation"]=>
      string(0) ""
      ["MobilePhone"]=>
      string(0) ""
    }
    ["ActiveCust"]=>
    array(1) {
      ["ActiveCust"]=>
      string(4) "true"
    }
  }
  [1]=>
  array(4) {
    ["Context"]=>
    array(3) {
      ["B1DBName"]=>
      string(11) "SGL_WebTest"
      ["B1DefaultPriceListNumber"]=>
      string(1) "1"
      ["B1UKStandardVatCode"]=>
      string(2) "O1"
    }
    ["WebsiteName"]=>
    array(1) {
      ["WebsiteName"]=>
      string(12) "Test webiste"
    }
    ["Cust"]=>
    array(13) {
      ["CardCode"]=>
      string(0) ""
      ["WebPassword"]=>
      string(0) ""
      ["EmailAddress"]=>
      string(19) "jessica@jessica.com"
      ["Title"]=>
      string(0) ""
      ["FirstName"]=>
      string(7) "Jessica"
      ["Surname"]=>
      string(5) "James"
      ["Telephone"]=>
      string(11) "020 4764777"
      ["WebID"]=>
      string(5) "28882"
      ["VATNumber"]=>
      string(0) ""
      ["FaxNumber"]=>
      string(0) ""
      ["Telephone2"]=>
      string(0) ""
      ["Organisation"]=>
      string(0) ""
      ["MobilePhone"]=>
      string(0) ""
    }
    ["ActiveCust"]=>
    array(1) {
      ["ActiveCust"]=>
      string(4) "true"
    }
  }
}
Error!<br />SOAP-ERROR: Encoding: object has no 'ActiveCust' propertyobject(mysqli_result)#2 (5) {
  ["current_field"]=>
  int(0)
  ["field_count"]=>
  int(21)
  ["lengths"]=>
  NULL
  ["num_rows"]=>
  int(2)
  ["type"]=>
  int(0)
}

必须一次向客户发送一个,而不是在集合中发送。