Mark Mark - 21 days ago 14
PHP Question

PHP soap xml vs SoapUI xml

I have a working SOAP UI xml, and I have my SOAP request XML and they are almost identical. SOAP UI works, mine gets a null response. Here's the SOAPUI XML first

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:get="http://www.cornerstoneondemand.com/Webservices/GetDetailsWebService">
<soapenv:Header>
<get:AuthHeader>
<get:CorpName>corp</get:CorpName>
<get:UserId>1234</get:UserId>
<get:Signature>ABC123</get:Signature>
</get:AuthHeader>
</soapenv:Header>
<soapenv:Body>
<get:GetDetails xmlns:get="http://www.cornerstoneondemand.com/Webservices/GetDetailsWebService">
<get:object_id>qwerty-123</get:object_id>
</get:GetDetails>
</soapenv:Body>
</soapenv:Envelope>


and here is my PHP code and the request.

$client=new SoapClient($wsdl,array('trace' => 1, 'exception' => 0));

$auth = array(
'CorpName' => $CorpName,
'UserId' => $username,
'Signature' => $Signature
);
$header = new SoapHeader('http://www.cornerstoneondemand.com/Webservices/GetDetailsWebService','AuthHeader',$auth,false);
$client->__setSoapHeaders($header);

$parm[] = new SoapVar($LOid, XSD_STRING, null, null, 'object_id' );


var_dump($client->GetDetails( new SoapVar($parm, SOAP_ENC_OBJECT) )); //output is NULL


//and the PHP request:

print_r($client->__getLastRequest());
output is

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.cornerstoneondemand.com/Webservices/GetDetailsWebService">
<SOAP-ENV:Header>
<ns1:AuthHeader>
<ns1:CorpName>corp</ns1:CorpName>
<ns1:UserId>1234</ns1:UserId>
<ns1:Signature>ABC123</ns1:Signature>
</ns1:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:GetDetails>
<object_id>qwerty-123</object_id>
</ns1:GetDetails>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


I can't tell if I'm close to creating a good request, or miles off. I'm working to make the PHP request match SOAPUI's since it works and mine doesn't.

ThW ThW
Answer

The contain the nearly same information. Namespace prefixes for element nodes are exchangeable and optional. So all these 3 variants are resolved to and element node with the local name Envelope in the namespace http://schemas.xmlsoap.org/soap/envelope/.

  • <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>
  • <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
  • <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>

You can read the element name as {http://schemas.xmlsoap.org/soap/envelope/}:Envelope.

The same goes for the get vs ns1 namespaces prefixes. They both resolve to the same actual namespace.

But the element object_id has no namespace you XML. The sixth argument of the SoapVar constructor is the node namespace so you might want to try:

$namespace = 'http://www.cornerstoneondemand.com/Webservices/GetDetailsWebService';
$parm[] = new SoapVar($LOid, XSD_STRING, null, null, 'object_id', $namespace);