VMware {code} Community
mdvlinguest
Contributor
Contributor
Jump to solution

Getting ServerFaultCode exception when trying to get refrance to a VM

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.

0 Kudos
1 Solution

Accepted Solutions
stumpr
Virtuoso
Virtuoso
Jump to solution

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;

Reuben Stump | http://www.virtuin.com | @ReubenStump

View solution in original post

0 Kudos
22 Replies
stumpr
Virtuoso
Virtuoso
Jump to solution

How are you getting the SearchIndex object moref?  Do you get it from ServiceContent or do you make it yourself?

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
mdvlinguest
Contributor
Contributor
Jump to solution

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

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

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?

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
mdvlinguest
Contributor
Contributor
Jump to solution

Hi.

service instance object which I get by RetrieveServiceContent does not have moref property. How do I get it?

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

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>

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
mdvlinguest
Contributor
Contributor
Jump to solution

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]

0 Kudos
mdvlinguest
Contributor
Contributor
Jump to solution

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]

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

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.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
mdvlinguest
Contributor
Contributor
Jump to solution

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.

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

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.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
mdvlinguest
Contributor
Contributor
Jump to solution

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.

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

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

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
mdvlinguest
Contributor
Contributor
Jump to solution

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>

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

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;

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
mdvlinguest
Contributor
Contributor
Jump to solution

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 ( )

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

What was the XML sent?

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
mdvlinguest
Contributor
Contributor
Jump to solution

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 ( )

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

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;                           

  }

?>

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
mdvlinguest
Contributor
Contributor
Jump to solution

So why I am getting empty object? How do I fix it?

0 Kudos