Retrieves a single company object based on the key value supplied.
Parameter |
Type |
Description |
---|---|---|
key |
The company key object that specifies the company to retrieve. |
|
context |
Specifies information about how the method will be called. |
Value |
Type |
Description |
---|---|---|
GetCompanyByKeyResult |
A company object. |
The following C# example retrieves the company with the key value “-1”. The name of the company is displayed in a message box.
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; Company company; // Create an instance of the service DynamicsGP wsDynamicsGP = new DynamicsGP(); // Be sure that default credentials are being used wsDynamicsGP.UseDefaultCredentials = true; // Create a context with which to call the service context = new Context(); // Set up the context object // To retrieve from the system database, set the organization key to null context.OrganizationKey = null; // Specify a company to retrieve (sample company) companyKey = new CompanyKey(); companyKey.Id = (-1); // Retrieve the company object for the sample company company = wsDynamicsGP.GetCompanyByKey(companyKey, context); // Display the company name MessageBox.Show("Company name: " + company.Name); } } }
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; Company company; // Create an instance of the service DynamicsGPClient wsDynamicsGP = new DynamicsGPClient(); // Create a context with which to call the service context = new Context(); // Set up the context object // To retrieve from the system database, set the organization key to null context.OrganizationKey = null; // Specify a company to retrieve (sample company) companyKey = new CompanyKey(); companyKey.Id = (-1); // Retrieve the company object for the sample company company = wsDynamicsGP.GetCompanyByKey(companyKey, context); // Display the company name MessageBox.Show("Company name: " + company.Name); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }