php soapclient返回null但getPreviousResults有正确的结果

I've ran into trouble with SOAP, I've never had this issue before and can't find any information on line that helps me solve it.

The following code

$wsdl = "path/to/my/wsdl";
$client = new SoapClient($wsdl, array('trace' => true));
//$$textinput is passed in and is a very large string with rows in <item></item> tags
$soapInput = new SoapVar($textinput, XSD_ANYXML);
$res = $client->dataprofilingservice(array("contents" => $soapInput));
$response = $client->__getLastResponse();

var_dump($res);//outputs null
var_dump($response);//provides the proper response as I would expect.

I've tried passing params into the SoapClient constructor to define soap version but that didnt' help. I've also tried it with the trace param set to false and not present which as expected made $response null but $res was still null. I've tried the code on both a linux and windows install running Apache.

The function definition in the WSDL is (xxxx is for security reasons)

<portType name="xxxxServiceSoap">
 <operation name="dataprofilingservice">
  <input   message="tns:dataprofilingserviceSoapIn"/>
  <output message="tns:dataprofilingserviceSoapOut"/>
 </operation>
</portType>

I have it working using the __getLastResponse() but its annoying me it will not work properly.

I've put together a small testing script, does anyone see any issues here. Do I need a structure for the return type?

//very simplifed dataset that would normally be 
//read in from a CSV file of about 1mb
$soapInput = getSoapInput("asdf,qwer
zzxvc,ewrwe
23424,2113");
$wsdl = "path to wsdl";

try {
  $client = new SoapClient($wsdl,array('trace' => true,'exceptions' => true));

} catch (SoapFault $fault) {
  $error = 1;
  var_dump($fault);
} 

try {
    $res = $client->dataprofilingservice(array("contents" => $soapInput));
    $response = $client->__getLastResponse();
    echo htmlentities($client->__getLastRequest());//proper request echoed
    echo '<hr>';
    var_dump($res);//null

    echo "<hr>";
    echo(htmlentities($response));//proper response echoed
} catch (SoapFault $fault) {
    $error = 1;
    var_dump($fault);

}         
function getSoapInput($input){
$rows = array();
    $userInputs = explode("
", $input);

    $userInputs = array_filter($userInputs);
    //
    $inputTemplate = " <contents>%s</contents>";
    $rowTemplate = "<Item>%s</Item>";
    //
    $soapString = "";
    foreach ($userInputs as $row) {
        // sanitize
        $row = htmlspecialchars(addslashes($row));
        $xmlStr = sprintf($rowTemplate, $row);
        $rows[] = $xmlStr;
    }
    $textinput = sprintf($inputTemplate, implode(PHP_EOL, $rows));
    $soapInput = new SoapVar($textinput, XSD_ANYXML);

   return $soapInput;

}

Ok after much digging it is related to relative namespaces, it appears that PHP doesn't handle them well within the WSDL or the SOAP Envelope. So since I don't have control of the SOAP Server I will continue to get the response via __getLastResponse();.

Hopefully this will save some people some time it was hard to find.

You are mixing things here. __getLastResponse() returns the bare XML string response from the server if you make use of the 'trace' => true option. That is for debugging only.

So regardless whether 'trace' => true or not, the method which you would like to call originally returns the same and that is totally normal. Setting tracing to on won't change the behaviour, it just offers an additional feature, the return value for __getLastResponse().

As the SoapClient does not throw any exception I'd say that your call is going okay and NULL is a valid return value.

You might want to provide the actual XML string and/or the WSDL defintion so that one could inspect if that's the case or not.