我正在尝试构建脚本以从Taleo下载空缺职位。我有这个工作在SOAP UI中。我发送了请求,响应中包含了我请求的所有数据。
请求:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.taleo.com/ws/tee800/2009/01/find"
xmlns:ns2="http://itk.taleo.com/ws/query">
<SOAP-ENV:Body>
<ns1:findPartialEntities>
<ns1:mappingVersion>http://www.taleo.com/ws/art750/2006/12</ns1:mappingVersion>
<ns1:query>
<ns2:query projectedClass="Requisition" alias="Find Open and Posted Requisitions">
<ns2:subQueries/>
<ns2:projections>
<ns2:projection alias="Ref">
<ns2:field path="Requisition,ContestNumber"/>
</ns2:projection>
</ns2:projections>
</ns2:query>
</ns1:query>
<ns1:attributes>
<ns1:entry>
<ns1:key>pageindex</ns1:key>
<ns1:value>1</ns1:value>
</ns1:entry>
<ns1:entry>
<ns1:key>pagingsize</ns1:key>
<ns1:value>2</ns1:value>
</ns1:entry>
</ns1:attributes>
</ns1:findPartialEntities>
</SOAP-ENV:Body>
响应:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ns1:findPartialEntitiesResponse xmlns:ns1="http://www.taleo.com/ws/tee800/2009/01/find">
<root:Entities pageIndex="1" pageCount="585" pagingSize="2" entityCount="1169" xmlns:root="http://www.taleo.com/ws/tee800/2009/01/find" xmlns:e="http://www.taleo.com/ws/art750/2006/12" xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07">
<e:Entity xsi:type="e:Requisition"/>
<e:Entity xsi:type="e:Requisition">
<e:ContestNumber>1500000L</e:ContestNumber>
</e:Entity>
</root:Entities>
</ns1:findPartialEntitiesResponse>
</soap:Body>
</soap:Envelope>
因此,我尝试将其翻译为PHP脚本。我可以在响应中看到工作角色,但是它们是空对象。我不确定如何访问数据。这是我的剧本。
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl', 900);
ini_set('default_socket_timeout', 15);
ini_set('use_soap_error_handler', true);
error_reporting(E_ALL);
date_default_timezone_set('UCT');
class taleo_test{
private $url = 'https://URL&wsdl';
private $username = '******';
private $password = '********';
public function __construct(){
}
public function connect(){
$options = array(
'login' => $this->username,
'password' => $this->password,
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_NONE,
'soap_version'=>SOAP_1_1
);
$query = [
'query' => [
'projectedClass' => "Requisition",
'alias' => "Find Open and Posted Requisitions",
'subQueries' => '',
'projections' => [
'projection' => [
'alias' => "Ref",
'field' => [
'path' => 'Requisition,ContestNumber'
]
]
]
]
];
$attributes = [
"entry" => [
['key' => 'pageindex', 'value' => '1'],
['key' => 'pagingsize', 'value' => '5']
]
];
try {
$client = new SoapClient($this->url, $options);
$arguments = array(
'mappingVersion' => 'http://www.taleo.com/ws/art750/2006/12',
'query' => $query,
'attributes' => $attributes
);
$results = $client->__soapCall("findPartialEntities", array($arguments));
echo "REQUEST:\n" . $client->__getLastRequest() . "\n\n";
echo "RESPONSE:\n" . $client->__getLastResponse() . "\n\n";
var_dump($results);
} catch (Exception $e) {
echo '<pre>';
echo $e->getMessage();
echo '<hr>';
echo $e->getTraceAsString();
echo htmlentities($client->__getLastRequest());
echo '<br>@@<hr><br>';
echo htmlentities($client->__getLastResponse());
echo '</pre>';
}
}
}
$taleo = new taleo_test;
$data = $taleo->connect();
$ client-> __ getLastResponse()的回显向我显示PHP不会向我显示的数据。
这是PHP文件的结果:
<hr>REQUEST:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.taleo.com/ws/tee800/2009/01/find" xmlns:ns2="http://itk.taleo.com/ws/query"><SOAP-ENV:Body> <ns1:findPartialEntities><ns1:mappingVersion>http://www.taleo.com/ws/art750/2006/12</ns1:mappingVersion><ns1:query><ns2:query projectedClass="Requisition" alias="Find Open and Posted Requisitions"><ns2:subQueries/><ns2:projections><ns2:projection alias="Ref"><ns2:field path="Requisition,ContestNumber"/></ns2:projection></ns2:projections></ns2:query></ns1:query><ns1:attributes><ns1:entry><ns1:key>pageindex</ns1:key><ns1:value>1</ns1:value></ns1:entry><ns1:entry><ns1:key>pagingsize</ns1:key><ns1:value>5</ns1:value></ns1:entry></ns1:attributes></ns1:findPartialEntities></SOAP-ENV:Body></SOAP-ENV:Envelope>
RESPONSE:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body> <ns1:findPartialEntitiesResponse xmlns:ns1="http://www.taleo.com/ws/tee800/2009/01/find"><root:Entities xmlns:root="http://www.taleo.com/ws/tee800/2009/01/find" xmlns:e="http://www.taleo.com/ws/art750/2006/12" xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07" pageIndex="1" pageCount="234" pagingSize="5" entityCount="1169"><e:Entity xsi:type="e:Requisition"/><e:Entity xsi:type="e:Requisition"><e:ContestNumber>1500000L</e:ContestNumber></e:Entity><e:Entity xsi:type="e:Requisition"><e:ContestNumber>1500000N</e:ContestNumber></e:Entity><e:Entity xsi:type="e:Requisition"><e:ContestNumber>1500000M</e:ContestNumber></e:Entity><e:Entity xsi:type="e:Requisition"><e:ContestNumber>1500000S</e:ContestNumber></e:Entity></root:Entities></ns1:findPartialEntitiesResponse></soap:Body></soap:Envelope>
object(stdClass)#3 (1) {
["Entities"]=>
object(stdClass)#4 (5) {
["Entity"]=>
array(5) {
[0]=>
object(stdClass)#5 (0) {
}
[1]=>
object(stdClass)#6 (0) {
}
[2]=>
object(stdClass)#7 (0) {
}
[3]=>
object(stdClass)#8 (0) {
}
[4]=>
object(stdClass)#9 (0) {
}
}
["pageIndex"]=>
string(1) "1"
["pageCount"]=>
string(3) "234"
["pagingSize"]=>
string(1) "5"
["entityCount"]=>
string(4) "1169"
}
}
我说过一些评论,说这可能是一个命名空间问题,但是不确定如何修改,或者如果不是问题,那么如何获取所需的数据(不必诉诸使用调试SOAP响应并将其解析为XML)。
任何帮助将不胜感激。
谢谢