7

Here is the data from wsdl

<s:element name="CreateDraftLead">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="formId" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="FirstName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="LastName" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="Gender" nillable="true" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="AgeGroup" nillable="true" type="s:int"/>
<s:element minOccurs="0" maxOccurs="1" name="MobilePhone" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="Birthday" nillable="true" type="s:dateTime"/>
<s:element minOccurs="0" maxOccurs="1" name="District" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="email" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Region" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="LocationId" nillable="true" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="LeadSourceId" nillable="true" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="CompanyId" nillable="true" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="SourceCampaignId" nillable="true" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="AllowEmail" nillable="true" type="s:boolean"/>
<s:element minOccurs="0" maxOccurs="1" name="Questions" type="tns:ArrayOfQuestion"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="ArrayOfQuestion">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="Question" nillable="true" type="tns:Question"/>
</s:sequence>
</s:complexType>
<s:complexType name="Question">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Key" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Value" type="s:string"/>
</s:sequence>
</s:complexType>

And here is my attempt code

$client = new SoapClient("http://demo/demo.asmx?wsdl", array('trace' => 1, "exception" => 0));


        $data = array(
            'formId' => 1,
            'LocationId' => 1,
            'FirstName' => 'test',
            'LastName' => 'test',
            'MobilePhone' => 11111111,
            'email' => 'test@test.com',
            'AllowEmail' => 0,
            'Region' => 'HK',
            'LeadSourceId' => 11,
            'Questions' => array(
                "Question" => array("AgeGroup" => 10),
                "Question" => array("Gender" => 1),
                "Question" => array("Remarks" => 'test'),
                "Question" => array("Are you currently a member of any yoga or fitness centre?  " => 'Yes'),
            )
        );



        $result = $client->CreateDraftLead(array('parameters' => $data));

        var_dump($result);

Is this caused by the structure of the input data, how to fix that? Thanks for helping.

Error message:

Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in C:\xampp\htdocs\test_soap.php:60 Stack trace: #0 C:\xampp\htdocs\test_soap.php(60): SoapClient->__call('CreateDraftLead', Array) #1 C:\xampp\htdocs\test_soap.php(60): SoapClient->CreateDraftLead(Array) #2 {main} thrown in C:\xampp\htdocs\test_soap.php on line 60

Updated:

Thanks for helping. right now can send to server

<?php
$client = new SoapClient("http://demo/demo.asmx?wsdl");

$data = array(
    'formId' => '1',
    'FirstName' => 'test',
    'LastName' => 'test',
    //'Gender' => 1,
    //'AgeGroup' => 10,
    'MobilePhone' => '11111111',
    'Birthday' => null,
    'District' => 'HK',
    'email' => 'test@test.com',
    'Region' => 'HK',
    'LocationId' => 1,
    'LeadSourceId' => 11,
    'CompanyId' => null,
    'SourceCampaignId' => null,
    'AllowEmail' => false,
    'Questions' => array(
        "Question" => array("AgeGroup" => 10),
        "Question" => array("Gender" => 1),
        "Question" => array("Remarks" => 'test'),
        "Question" => array("Are you currently a member of any yoga or fitness centre?  " => 'Yes'),
    )
);

$result = $client->__soapCall("CreateDraftLead", array($data));

var_dump($result);
?>

Problems remain are :

1) AllowEmail takes boolean but either 0,1,true,false return error : Invalid column name 'false' / Invalid column name 'true' from the server , but it is not exception

2) is minOccurs='1' means must provide? as tested can ignore the field and server still return success

Thanks for great effort.

user782104
  • 13,233
  • 55
  • 172
  • 312

3 Answers3

7

Please try out the following (not tested):

<?php
$client = new SoapClient("http://demo/demo.asmx?wsdl", array('trace' => 1, "exception" => 0));

$data = array(
    'formId' => 1,
    'LocationId' => 1,
    'FirstName' => 'test',
    'LastName' => 'test',
    'MobilePhone' => 11111111,
    'email' => 'test@test.com',
    'AllowEmail' => 0,
    'Region' => 'HK',
    'LeadSourceId' => 11,
    'Questions' => array(
        "Question" => array("AgeGroup" => 10),
        "Question" => array("Gender" => 1),
        "Question" => array("Remarks" => 'test'),
        "Question" => array("Are you currently a member of any yoga or fitness centre?  " => 'Yes'),
    )
);

$result = $client->__soapCall("CreateDraftLead", array($data));

var_dump($result);

Also it seems that you do not provide all neccessary infomration like Gender and so on.. you should check this aswell.

Michael
  • 663
  • 1
  • 13
  • 28
  • thanks now the input is ok , the only problem is server return ["CreateDraftLeadResult"]=> object(stdClass)#3 (3) { ["status"]=> bool(false) ["Message"]=> string(28) "Invalid column name 'false'." ["FormId"]=> string(1) "1" } – user782104 May 13 '16 at 08:54
  • it is caused by the 'AllowEmail' , which accept the boolean type, how to post the boolean type to SOAP, tested 0 , false are not ok – user782104 May 13 '16 at 09:03
  • 1
    In general `0`,`1`, `false` and `true`are valid values (case sensitive) – Michael May 13 '16 at 09:10
  • thanks for quick reply. Tested all 0,1, false, true, return the error "Invalid column name false" . But if I ignore it / post null, the server return success, is this possibly the service problem? – user782104 May 13 '16 at 09:14
  • 1
    Can you update the array you send to the server? seems to be a problem in the data structure. – Michael May 13 '16 at 09:19
  • 1
    Try to send `'AllowEmail' => "0",` instead of `'AllowEmail' => 0,` this might fix the prob – Michael May 13 '16 at 09:23
  • still same error message, and I found that "0" ,0 , false are interchangeable , also mean false – user782104 May 13 '16 at 09:25
  • 1
    Might be a problem with the service, as far as this is not neccessary for you, you might just skip this value – Michael May 13 '16 at 09:29
3

You can use "0" or intval(false)

<?php
  $client = new SoapClient("http://demo/demo.asmx?wsdl", array('trace' => 1, "exception" => 0));

 $data = array(
   'formId' => 1,
   'LocationId' => 1,
   'FirstName' => 'test',
   'LastName' => 'test',
   'MobilePhone' => 11111111,
   'email' => 'test@test.com',
   'AllowEmail' => "0",
   'Region' => 'HK',
   'LeadSourceId' => 11,
   'Questions' => array(
       "Question" => array("AgeGroup" => 10),
       "Question" => array("Gender" => 1),
       "Question" => array("Remarks" => 'test'),
       "Question" => array("Are you currently a member of any yoga or fitness centre?  " => 'Yes'),
   )
 );

$result = $client->__soapCall("CreateDraftLead", array($data));

var_dump($result);

OR

<?php
$client = new SoapClient("http://demo/demo.asmx?wsdl", array('trace' => 1, "exception" => 0));

$data = array(
   'formId' => 1,
   'LocationId' => 1,
   'FirstName' => 'test',
   'LastName' => 'test',
   'MobilePhone' => 11111111,
   'email' => 'test@test.com',
   'AllowEmail' => intval(false),
   'Region' => 'HK',
   'LeadSourceId' => 11,
   'Questions' => array(
       "Question" => array("AgeGroup" => 10),
       "Question" => array("Gender" => 1),
       "Question" => array("Remarks" => 'test'),
       "Question" => array("Are you currently a member of any yoga or fitness centre?  " => 'Yes'),
   )
);

$result = $client->__soapCall("CreateDraftLead", array($data));

var_dump($result);
KARTHI SRV
  • 499
  • 4
  • 20
3

I would test one more trick for sending boolean to your service:

// most probably a solution
'AllowEmail' => new \SoapVar('true', XSD_STRING, 's:boolean')
// or less probably solution, but still possible I guess
'AllowEmail' => new \SoapVar('true', XSD_BOOLEAN, 's:boolean')

I assume this is way to do it, as when you are trying to send 0|1|true|false it returns a wierd error of no such COLUMN.

2) is minOccurs='1' means must provide? as tested can ignore the field and server still return success

I guess so. But it still stays on implementation on other side. I was integrating once an API with WSDL extremety far from what you were able to do with it.

yergo
  • 4,761
  • 2
  • 19
  • 41
  • sorry for late reply, both of them still return the error : Invalid column name 'true'. – user782104 May 20 '16 at 08:33
  • 1
    So I would send it to support of API you are working with. It is obviously a mistake on their side for me. – yergo May 20 '16 at 08:51