2016-04-06 16 views
6

Dưới đây là các dữ liệu từ wsdlLỗi: "Object tài liệu tham khảo không được đặt để một thể hiện của một đối tượng" khi gọi cilent SOAP trong 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> 

Và đây là mã cố gắng của tôi

$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 điều này gây ra bởi cấu trúc của dữ liệu đầu vào, cách khắc phục điều đó? Cảm ơn bạn đã giúp đỡ.

Thông báo lỗi:

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 

Cập nhật:

Cảm ơn vì đã giúp. ngay bây giờ có thể gửi đến máy chủ

<?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); 
?> 

Vấn đề vẫn là:

1) AllowEmail mất boolean nhưng một trong hai 0,1, đúng, lỗi trở lại sai: tên cột không hợp lệ 'false' tên cột/không hợp lệ ' đúng 'từ máy chủ, nhưng nó không phải là ngoại lệ

2) là minOccurs =' 1 'có nghĩa là phải cung cấp? như được kiểm tra có thể bỏ qua trường và máy chủ vẫn trả về thành công

Cảm ơn vì nỗ lực tuyệt vời.

+0

đây có phải là nguồn wsdl đầy đủ không? – Michael

+0

Nếu câu hỏi ban đầu của bạn đã được trả lời, bạn nên đánh dấu câu trả lời được chấp nhận, không chỉnh sửa câu hỏi của bạn để thêm các câu hỏi khác. – miken32

Trả lời

6

hãy thử những điều sau đây (không kiểm tra):

<?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); 

Cũng có vẻ như bạn không cung cấp tất cả các infomration cần thiết như Gender và vân vân .. bạn nên kiểm tra là tốt này.

+0

nhờ đầu vào là ok, vấn đề duy nhất là máy chủ trả về ["CreateDraftLeadResult"] => object (stdClass) # 3 (3) {["status"] => bool (false) ["Message"] => string (28) "Tên cột không hợp lệ 'sai'." ["FormId"] => string (1) "1"} – user782104

+0

nó được gây ra bởi 'AllowEmail', chấp nhận kiểu boolean, cách đăng loại boolean lên SOAP, được kiểm tra 0, false không ok – user782104

+1

Nói chung '0',' 1', 'false' và' true'are giá trị hợp lệ (phân biệt chữ hoa chữ thường) – Michael

3

Bạn có thể sử dụng "0" hoặc 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); 

HOẶC

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

xin lỗi vì trả lời muộn. nó trả về tên cột không hợp lệ 'false'. – user782104

3

tôi sẽ kiểm tra lừa thêm một để gửi boolean dịch vụ của bạn:

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

Tôi cho rằng đây là cách để làm điều đó, như khi bạn đang cố gắng gửi 0|1|true|false nó trả về một lỗi đáng kinh ngạc của không có COLUMN.

2) là minOccurs = '1' có nghĩa là phải cung cấp? như được kiểm tra có thể bỏ qua trường và máy chủ vẫn trả về thành công

Tôi đoán vậy. Nhưng nó vẫn tiếp tục thực hiện ở phía bên kia. Tôi đã tích hợp một API với WSDL cực xa so với những gì bạn có thể làm với nó.

+0

xin lỗi vì trả lời muộn, cả hai người trong số họ vẫn trả lại lỗi: Tên cột không hợp lệ 'true'. – user782104

+1

Vì vậy, tôi sẽ gửi nó để hỗ trợ API bạn đang làm việc. Nó rõ ràng là một sai lầm về phía họ đối với tôi. – yergo

Các vấn đề liên quan