Retrieves a single service object based on the specified item key.
Parameter |
Type |
Description |
---|---|---|
key |
The item key object that specifies the service to retrieve. |
|
context |
Specifies information about how the method will be called. |
Value |
Type |
Description |
---|---|---|
GetServiceByKeyResult |
A service object. |
The following C# example retrieves a service object with the key value “SPLN-TWO-0001”. A message box displays the service description.
Legacy endpoint
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; ItemKey serviceKey; Service service; // Create an instance of the service DynamicsGP wsDynamicsGP = new DynamicsGP(); // Be sure the default credentials are used wsDynamicsGP.UseDefaultCredentials = true; // Create a context with which to call the service context = new Context(); // Specify which company to use (sample company) companyKey = new CompanyKey(); companyKey.Id = (-1); // Set up the context object context.OrganizationKey = (OrganizationKey)companyKey; // Create an item key to specify the service serviceKey = new ItemKey(); serviceKey.Id = "SPLN-TWO-0001"; // Retrieve the service service = wsDynamicsGP.GetServiceByKey(serviceKey, context); // Display the service description MessageBox.Show("Service description: " + service.Description); } } }
Native endpoint
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; ItemKey serviceKey; Service service; // Create an instance of the service DynamicsGPClient wsDynamicsGP = new DynamicsGPClient(); // Create a context with which to call the service context = new Context(); // Specify which company to use (sample company) companyKey = new CompanyKey(); companyKey.Id = (-1); // Set up the context object context.OrganizationKey = (OrganizationKey)companyKey; // Create an item key to specify the service serviceKey = new ItemKey(); serviceKey.Id = "SPLN-TWO-0001"; // Retrieve the service service = wsDynamicsGP.GetServiceByKey(serviceKey, context); // Display the service description MessageBox.Show("Service description: " + service.Description); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }