.NET Example of Connecting to the Lookup Service and Retrieving a Service Registration Object

The example is based on the code from the
LookupServiceHelper.cs
sample file.
This example uses the steps that are described in the Connect to the Lookup Service and Retrieve the Service Registration Object procedure.
For a complete and up-to-date version of the sample code, see the vSphere Automation SDK .NET samples at GitHub.
... // 1 - Create a custom binding for SOAP messages. var customBinding = new CustomBinding(); var textMessageEncoding = new TextMessageEncodingBindingElement(); textMessageEncoding.MessageVersion = MessageVersion.Soap11; var transport = new HttpsTransportBindingElement(); transport.MaxReceivedMessageSize = 2147483647; customBinding.Elements.Add(textMessageEncoding); customBinding.Elements.Add(transport); // 2 - Create an object that encapsulates the Lookup Service URL. var address = new EndpointAddress(lsUrl); // 3 - Create a connection object to communicate with the Lookup Service. lsPort = new LsPortTypeClient(customBinding, address); // 4 - Manufacture a managed object reference. var serviceInstanceRef = new ManagedObjectReference(); serviceInstanceRef.type = "LookupServiceInstance"; serviceInstanceRef.Value = "ServiceInstance"; // 5 - Retrieve the ServiceContent managed object. serviceContent = lsPort.RetrieveServiceContent(serviceInstanceRef); // 6 - Retrieve the service registration object. serviceRegistration = serviceContent.serviceRegistration;