2016-04-06 22 views
6

Ecco i dati da WSDLerrore: "riferimento oggetto non impostato a un'istanza di un oggetto" quando si chiama SOAP cilent in PHP

<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> 

E qui è il mio codice tentativo

$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' => '[email protected]', 
      '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 questo causato dalla struttura dei dati di input, come risolverlo? Grazie dell'aiuto.

Messaggio di errore:

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 

Aggiornato:

Grazie per l'aiuto. in questo momento in grado di inviare al 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' => '[email protected]', 
    '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); 
?> 

problemi rimangono sono:

1) AllowEmail prende booleano ma o 0,1, vero, errore return false: valido nome di colonna 'false' nome di colonna/non valido ' true 'dal server, ma non fa eccezione

2) è minOccurs =' 1 'significa deve fornire? come testato può ignorare il campo e il server restituisce ancora successo

Grazie per il grande sforzo.

+0

è la fonte completa di wsdl? – Michael

+0

Se la tua domanda originale è stata risposta, dovresti contrassegnare la risposta accettata, non modificare la tua domanda per aggiungere altre domande. – miken32

risposta

6

Si prega di provare quanto segue (non testato):

<?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' => '[email protected]', 
    '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); 

Inoltre sembra che non si forniscono tutte infomration neccessary come Gender e così via .. si dovrebbe verificare questo pure.

+0

grazie ora l'input è ok, l'unico problema è il ritorno del server ["CreateDraftLeadResult"] => oggetto (stdClass) # 3 (3) {["status"] => bool (false) ["Message"] => stringa (28) "Nome colonna non valido 'false'." ["FormId"] => string (1) "1"} – user782104

+0

è causato da 'AllowEmail', che accetta il tipo booleano, come postare il tipo booleano su SOAP, testato 0, false non ok – user782104

+1

In generale '0',' 1', 'false' e' true' sono valori validi (maiuscole e minuscole) – Michael

3

È possibile utilizzare "0" o 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' => '[email protected]', 
    '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); 

O

<?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' => '[email protected]', 
    '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); 
+0

scusate per la risposta in ritardo. restituisce il nome della colonna non valido 'false'. – user782104

3

vorrei testare più un trucco per l'invio booleano al vostro servizio:

// 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') 

Presumo che questo è il modo per farlo, come quando si sta tentando di inviare 0|1|true|false restituisce un errore errato di senza COLUMN.

2) è minOccurs = '1' significa deve fornire? come testato può ignorare il campo e il server restituisce ancora successo

Credo di sì. Ma continua a essere implementata dall'altra parte. Stavo integrando una volta un'API con l'estremità di WSDL lontana da ciò che eri in grado di fare con esso.

+0

scusa per la risposta tardiva, entrambi restituiscono ancora l'errore: Nome colonna non valido 'true'. – user782104

+1

Quindi vorrei inviarlo al supporto dell'API con cui stai lavorando. È ovviamente un errore dalla loro parte per me. – yergo

Problemi correlati