I'm trying to return a list of Customers from GP using Web Services, however I'm running into a problem when executing the query. I can confirm that the main connection to the Dynamics database is working as I can run a query to retrieve the list of Companies (this is how I retrieved the CompanyID key to use with my context for the Customer query.)
However, when I execute any sort of other query, it looks like the CompanyKey is getting set to zero (0) in the XML being sent to eConnect. The exception returned is "Microsoft.Dynamics.Security.NonExistentSecurityObjectException : The security object does not exist. Key = 0" When I look at the xml being sent to the service, I notice that the element is also set to 0, even though I explicitly set it the value of the Company I want to query (which in this case is 37 which I retrieved from doing the Company list query earlier.)
The full XML being sent is as follows:
<?xml version="1.0"?>
<RequestObjects>
<Context xmlns:xsi="www.w3.org/.../XMLSchema-instance" xmlns:xsd="www.w3.org/.../XMLSchema" xmlns="schemas.microsoft.com/.../01">
<OrganizationKey xsi:type="CompanyKey">
<Id>0</Id>
</OrganizationKey>
<CurrencyType>Transactional</CurrencyType>
</Context>
<CustomerCriteria xmlns:xsi="www.w3.org/.../XMLSchema-instance" xmlns:xsd="www.w3.org/.../XMLSchema">
<Scope>Return All</Scope>
</CustomerCriteria>
</RequestObjects>
As for the underlying C# code I'm using in my client app:
CompanyKey companyKey;
Context context;
DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();
context = new Context();
companyKey = new CompanyKey();
companyKey.Id = 37;
context.OrganizationKey = companyKey;
companies = wsDynamicsGP.GetCustomerList( new CustomerCriteria { }, context );
I've based my code on the examples given in the GP2010 Web Services developers manually straight from Microsoft.
*This post is locked for comments