PHP Soap Client __getLastRequest()为空

时间:2015-03-06 00:50:23

标签: php xml web-services soap wsdl

我不得不道歉,我意识到Stack Overflow上有很多这样的问题....甚至可能满满的......:)

我正在使用PHP内置的soap客户端对soap服务进行Web调用。 根据wsdl,它期望我传递的项目是一个字符串。没有文档而不是wsdl和公司声明它是xml。 所以我已经构建了一个对象,并在php中将其转换为xml,并确认xml看起来正确无误。

这是我班上的方法

$options = array( 'trace' => 1, 'exceptions' => 1, "features" => SOAP_SINGLE_ELEMENT_ARRAYS);   
    $client = new SoapClient($this->submitUrl."?WSDL", $options);
    $client->InsertLeadInformation($xml);

    print_r($client->__getLastRequest());

我已经回应了调用上方的xml并且它看起来是正确的但是当我传递它__getLastRequest()时,soap信封是空的吗?

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://xxxxxxxx.com/webservices2"><SOAP-ENV:Body><ns1:InsertLeadInformation/></SOAP-ENV:Body></SOAP-ENV:Envelope>
谁有任何想法?提前谢谢你

1 个答案:

答案 0 :(得分:0)

我能够解决这个问题,我不确定它是否需要在每个soap调用中使用这种方式但是我必须将传入的xml添加到索引为sLeadInfo的数组中,因为它包含xml中的元素。我之前添加了我的xml,但这似乎不起作用。您可以在gerenateXML()

的倒数第二行看到编辑

这是针对saleslogix的,只要有人好奇并寻找答案

private function generateXML(){
    $xml = new stdClass();
    $xml->LeadCapture = new stdClass();
    $xml->LeadCapture->Common = new stdClass();
    $xml->LeadCapture->Common->DataSource = $this->dataSource;
    $xml->LeadCapture->Common->TrackId = $this->trackId;
    $xml->LeadCapture->Common->leadSourceCode = $this->leadSourceCode;

    $xml->LeadCapture->Person = new stdClass();
    $xml->LeadCapture->Person->FirstName = $this->firstname;
    $xml->LeadCapture->Person->LastName = $this->lastName;
    $xml->LeadCapture->Person->Title = $this->title;
    $xml->LeadCapture->Person->Email = $this->email;
    $xml->LeadCapture->Person->Phone = $this->phone;
    $xml->LeadCapture->Person->Fax = $this->fax;
    $xml->LeadCapture->Person->Address1 = $this->address1;
    $xml->LeadCapture->Person->Address2 = $this->address2;
    $xml->LeadCapture->Person->City = $this->city;
    $xml->LeadCapture->Person->State = $this->state;
    $xml->LeadCapture->Person->PostalCode = $this->postalCode;
    $xml->LeadCapture->Person->Note = $this->note;

    $xml->LeadCapture->Company = new stdClass();
    $xml->LeadCapture->Company->CompanyName = $this->companyName;
    $xml->LeadCapture->Company->Address1 = $this->companyAddress1;
    $xml->LeadCapture->Company->Address2 = $this->companyAddress2;
    $xml->LeadCapture->Company->City = $this->companyCity;
    $xml->LeadCapture->Company->State = $this->companyState;
    $xml->LeadCapture->Company->PostalCode = $this->companyPostalCode;
    $xml->LeadCapture->Company->Country = $this->companyCountry;

    $result = array('sLeadInfo'=>php_object_to_xml::object_to_xml($xml));
    return $result;

private function submitDataSoap($xml) {
    $xmlstring = $xml;
    $options = array( 'trace' => 1, 'exceptions' => 1, "features" => SOAP_SINGLE_ELEMENT_ARRAYS);   
    $client = new SoapClient($this->submitUrl."?WSDL", $options);
    $result = $client->InsertLeadInformation($xmlstring);
    print_r($result);
    //print_r($xml);
    //print_r($client->__getLastRequest());
}