在PHP中调用SOAP cilent时,对象引用未设置为对象的实例

时间:2016-05-13 02:22:20

标签: php arrays soap wsdl soap-client

以下是来自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>

这是我的尝试代码

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

这是由输入数据的结构引起的,如何解决?谢谢你的帮助。

更新:

感谢您的建议,在使用小写到formId和电子邮件后,错误似乎仍然存在

以下是错误代码:

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

非常感谢。

0 个答案:

没有答案