1

I'm trying to post data to a .net web service and I receive the error : "SOAP-ERROR: Encoding: object has no 'ActiveCust' property".

Here is the 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>

<s:complexType name="B1Context">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="B1DBName" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="B1DefaultPriceListNumber" type="s:int"/>
<s:element minOccurs="0" maxOccurs="1" name="B1UKStandardVatCode" type="s:string"/>
</s:sequence>
</s:complexType>

<s:complexType name="Customer">
<s:complexContent mixed="false">
<s:extension base="tns:EntityObject">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="CardCode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="WebPassword" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="EmailAddress" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Title" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="FirstName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Surname" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Telephone" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="WebID" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="VATNumber" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="FaxNumber" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Telephone2" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Organisation" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="MobilePhone" type="s:string"/>
</s:sequence>
</s:extension>
</s:complexContent>
</s:complexType>

<s:complexType name="CustomAttribute">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="FieldName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="FieldValue" type="s:string"/>
</s:sequence>
</s:complexType>

and here is my code:

error_reporting(E_ALL);

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

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

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


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

$CustomerCustomAttrs=array(
    $CustomAttribute=array(
        "FieldName" => "",
        "FieldValue" => ""
    )
);

//Associative array
$params = array(
    $Context,
    $WebsiteName,
    $Cust,
    $ActiveCust,
    $CustomerCustomAttrs
);

//var_dump($params);

try {
    $client = new SoapClient("http://my.asmx?wsdl");
    $result = $client->SubmitNewCustomerToB1($params);

    var_dump($result);

} 
catch (Exception $e) 
{
    echo "Error!<br />";
    echo $e -> getMessage ();
}

The error I get: SOAP-ERROR: Encoding: object has no 'ActiveCust' property

Anyone can help me please ? Thank so much! Luca

Luca
  • 108
  • 1
  • 11
  • long time since I used SOAP, so just a few ideas via comment.. 1. your associative array `$params` is not associative (would need something like `'Cust' => $Cust, ..`). 2. I would try to call the wsdl function just with the fitting array, like `$client->SubmitNewCustomerToB1($ActiveCust);`. 3. complexeTypes can be difficult, I vaguely remember that maybe you need to wrap the parameter in a class – cypherabe Jan 09 '15 at 16:35
  • Thanks for the suggestion. Still no success. – Luca Jan 12 '15 at 09:15
  • maybe the examples in this Q/A help? http://stackoverflow.com/questions/11866425/soap-error-encoding-object-has-no-property - they build the parameter for complex type as objects, not arrays – cypherabe Jan 12 '15 at 09:32
  • Thanks cypherabe for your effective help ! – Luca Jan 12 '15 at 15:55

1 Answers1

0

the associative array was well formed. The problem was the last optional array $CustomerCustomAttrs, I removed it and the web service started working properly.

Old version

//Associative array
$params = array(
    $Context,
    $WebsiteName,
    $Cust,
    $ActiveCust,
    $CustomerCustomAttrs
);

New version

$params = array(
    'Context' => $Context,
    'WebsiteName' => $WebsiteName,
    'Cust' => $Cust,
    'ActiveCust' => $ActiveCust
);
Luca
  • 108
  • 1
  • 11