Retrieves a single company address object based on the key value supplied.
Parameter |
Type |
Description |
---|---|---|
key |
The company address key object that specifies the company address to retrieve. |
|
context |
Specifies information about how the method will be called. |
Value |
Type |
Description |
---|---|---|
GetCompanyAddressByKeyResult |
A company address object. |
The following C# example retrieves a the company address object with the key value “PRIMARY”. The organization key property of the context object specifies the company key. The street address 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; CompanyAddress companyAddress; CompanyAddressKey addressKey; // 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 a company address key object to retrieve the primary address addressKey = new CompanyAddressKey(); addressKey.Id = "PRIMARY"; // Retrieve the company address object companyAddress = wsDynamicsGP.GetCompanyAddressByKey(addressKey, context); // Display the primary street address MessageBox.Show("Primary street address: " + companyAddress.Line1); } } }
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; CompanyAddress companyAddress; CompanyAddressKey addressKey; // 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 a company address key object to retrieve the primary address addressKey = new CompanyAddressKey(); addressKey.Id = "PRIMARY"; // Retrieve the company address object companyAddress = wsDynamicsGP.GetCompanyAddressByKey(addressKey, context); // Display the primary street address MessageBox.Show("Primary street address: " + companyAddress.Line1); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }