Hi.
I am using PHP 5 and its builtin SoapClient to connect to vCenter 5.5 web service. Login and log out functions are working but when call any FindBy methods I get the following exception:
SoapFault exception: [ServerFaultCode] The object has already been deleted or has not been completely created
I suspect this is not an issue with parameters but is a general issue with method calls. Please assist me to pass this part of my development.
Thanks in advance.
Yup, look at your "_this" node, it's empty. But I just noticed that "SearchIndex" is capitalized. Perhaps it's returning null b/c the property name is 'searchIndex' not 'SearchIndex'?
$service_instance->searchIndex;
How are you getting the SearchIndex object moref? Do you get it from ServiceContent or do you make it yourself?
Hi.
Thanks for reply. I'm calling RetrieveServiceContent and get service instance then provide its SearchIndex property as _this to find methods. Should I created myself by using new soapvar?
Regards
No, you should use the moref provided by ServiceContent.
That error is usually the result of not having the right moref, or using a moref from a different session. Do you have your sample SOAP to review?
Hi.
service instance object which I get by RetrieveServiceContent does not have moref property. How do I get it?
The property 'searchIndex' of ServiceContent is the moref.
Just checked, SearchIndex is not session specific, so you're safe there. I think you'll need to post some of your code to get any better insights. Other functions are working, correct? Curious if you're handling cookies properly....but I would expect session invalid errors if you weren't authenticated.
Here's some valid XML from the Perl SDK -
Request -
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<FindByDnsName xmlns="urn:vim25"><_this type="SearchIndex">SearchIndex</_this>
<dnsName>esx-01.vlab.local</dnsName><vmSearch>0</vmSearch></FindByDnsName></soapenv:Body></soapenv:Envelope>
Response -
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<FindByDnsNameResponse xmlns="urn:vim25"><returnval type="HostSystem">host-30</returnval></FindByDnsNameResponse>
</soapenv:Body>
</soapenv:Envelope>
Hi.
Bellow is my whole code. Its a small script which logs on to the server and requests a reference to a VM.
[code]
<?
try
{
$client = new SoapClient("https://198.204.235.179/sdk/vimservice.wsdl", array('location'=>"https://198.204.235.179/sdk"));
// Setup service content
$soap_message["_this"] = new SoapVar("ServiceInstance", XSD_STRING, "ServiceInstance");
$result = $client->RetrieveServiceContent($soap_message);
$service_instance = $result->returnval;
//print_r($service_instance->content);
// Login example via serviceinstance
$soap_message["_this"] = $service_instance->sessionManager;
$soap_message["userName"] = "administrator";
$soap_message["password"] = "Cssrplinux2079!";
$result = $client->Login($soap_message);
$soap_session = $result->returnval;
//print_r($soap_session);
$soap_message["_this"] = $service_instance->SearchIndex;
//$soap_message["datacenter"] = "Virtual DC 1";
//$soap_message["path"] = "datastore2_vmserver2/Windows Base/Windows Base.vmx";
$soap_message["path"] = "Virtual DC1/vm/Linux Test";
$result = $client->FindByInventoryPath($soap_message);
print_r($result->returnval);
// Logout example
$soap_message["_this"] = $service_instance->sessionManager;
$result = $client->Logout($soap_message);
}
catch (Exception $e)
{
printf("%s\n",$e->__toString());
return false;
}
?>
[/code]
Hi.
Bellow is my whole code. Its a small script which logs on to the server and requests a reference to a VM.
[code]
<?
try
{
$client = new SoapClient("https://198.204.235.179/sdk/vimservice.wsdl", array('location'=>"https://198.204.235.179/sdk"));
// Setup service content
$soap_message["_this"] = new SoapVar("ServiceInstance", XSD_STRING, "ServiceInstance");
$result = $client->RetrieveServiceContent($soap_message);
$service_instance = $result->returnval;
//print_r($service_instance->content);
// Login example via serviceinstance
$soap_message["_this"] = $service_instance->sessionManager;
$soap_message["userName"] = "administrator";
$soap_message["password"] = "Cssrplinux2079!";
$result = $client->Login($soap_message);
$soap_session = $result->returnval;
//print_r($soap_session);
$soap_message["_this"] = $service_instance->SearchIndex;
//$soap_message["datacenter"] = "Virtual DC 1";
//$soap_message["path"] = "datastore2_vmserver2/Windows Base/Windows Base.vmx";
$soap_message["path"] = "Virtual DC1/vm/Linux Test";
$result = $client->FindByInventoryPath($soap_message);
print_r($result->returnval);
// Logout example
$soap_message["_this"] = $service_instance->sessionManager;
$result = $client->Logout($soap_message);
}
catch (Exception $e)
{
printf("%s\n",$e->__toString());
return false;
}
?>
[/code]
You may need to use the SoapVar method to generate the _this for the FindByInventoryPath call, that's the likely cause just from a quick glance. You could also have the SoapClient output the serialized SOAP envelope to review the differences to be sure.
Hi.
I changed my code to defind _this using the following code:
$soap_message["_this"] = new SoapVar(null, SOAP_ENC_OBJECT, "SearchIndex"); |
But it does not work! Result is the same.
Are you using the SoapClient that supports $SOAP->__getLastRequest()
?
If so, try to print out the request and post it here, from the XML I can probably deduce the issue.
Hi.
It catches the exception exactly on the line which calls teh FindByInventory soap method so it does not reach the line which calls getLastRequest.
That's right, never clear to call it. Take a look here, maybe some of these steps might help you get a trace print of the XML request to find the error -
Inspect XML created by PHP SoapClient call before/without sending the request - Stack Overflow
Hi.
THis the request if I set soap_message["_this"] = $service_instance->SearchIndex:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:vim25"><SOAP-ENV:Body><ns1:FindByInventoryPath><ns1:_this/><ns1:inventoryPath>Virtual DC1/vm/Linux Base</ns1:inventoryPath></ns1:FindByInventoryPath></SOAP-ENV:Body></SOAP-ENV:Envelope>
Yup, look at your "_this" node, it's empty. But I just noticed that "SearchIndex" is capitalized. Perhaps it's returning null b/c the property name is 'searchIndex' not 'SearchIndex'?
$service_instance->searchIndex;
Hi.
That simply fixed the exception. However result of calling method returns an empty object as result of call which has no returnval
stdClass Object ( )
What was the XML sent?
This is output:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:vim25"><SOAP-ENV:Body><ns1:FindByInventoryPath><ns1:_this type="SearchIndex">SearchIndex</ns1:_this><ns1:inventoryPath>Virtual DC1</ns1:inventoryPath></ns1:FindByInventoryPath></SOAP-ENV:Body></SOAP-ENV:Envelope>
stdClass Object ( )
It's working, you got back a managed object reference (object). PHP doesn't have full object awareness of the SDK objects.
It worked for me in any event. I have a DC01 in my inventory, I took your PHP, modified it and tested it:
$ php test.php
stdClass Object
(
[_] => datacenter-21
[type] => Datacenter
)
<?
try
{
$client = new SoapClient("https://172.16.254.105/sdk/vimService.wsdl", array('location'=>"https://172.16.254.105/sdk"));
// Setup service content
$soap_message["_this"] = new SoapVar("ServiceInstance", XSD_STRING, "ServiceInstance");
$result = $client->RetrieveServiceContent($soap_message);
$service_instance = $result->returnval;
//print_r($service_instance->content);
// Login example via serviceinstance
$soap_message["_this"] = $service_instance->sessionManager;
$soap_message["userName"] = "administrator@vlab";
$soap_message["password"] = "*";
$result = $client->Login($soap_message);
$soap_session = $result->returnval;
//print_r($soap_session);
$soap_message["_this"] = $service_instance->searchIndex;
//$soap_message["datacenter"] = "Virtual DC 1";
//$soap_message["path"] = "datastore2_vmserver2/Windows Base/Windows Base.vmx";
$soap_message["inventoryPath"] = "DC01";
$result = $client->FindByInventoryPath($soap_message);
print_r($result->returnval);
// Logout example
$soap_message["_this"] = $service_instance->sessionManager;
$result = $client->Logout($soap_message);
}
catch (Exception $e)
{
printf("%s\n",$e->__toString());
return false;
}
?>
So why I am getting empty object? How do I fix it?