Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

Web Service call overwrites CustomerKey

Posted on by 65

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

  • elmo Profile Picture
    elmo 447 on at
    RE: Web Service call overwrites CustomerKey

    Anthony I am having the same issue, could you give me code example to set IdSpecified to true?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web Service call overwrites CustomerKey

    I know this is an old call but I've just had the same issue and thought I'd add the answer for anyone else in the same boat. When configuring the CompanyKey object as well as setting the Id with the company id you also need to set IdSpecified to true. If IdSpecified is not set to true any value in Id is always reset to Zero.

  • Steve Kubis Profile Picture
    Steve Kubis on at
    RE: Web Service call overwrites CustomerKey

    That helps us narrow down the issue. A couple more thoughts...

    I see that you're directly assigning the company key to the organization key in the Context object. Those aren't the same type, so you normally have to cast the company key when it gets assigned. The code looks like this:

    // Set up the context

    context.OrganizationKey = (OrganizationKey)companyKey;

    Notice the (OrganizationKey) before companyKey. That's the cast that says to force this variable to be the correct type. Try this in your code to see if it helps.

    The last suggestion I have is to try compiling one of the web service sample applications (like Sales Document) and try it with your web service. That specific sample does retrieve a customer list, just like you're doing. It also retrieves the list of companies. That will help you verify that the web service is working correctly, and that the issue is in your code. You can also look at the sample code itself to see what's different from your code.

  • Nolan St. Martin Profile Picture
    Nolan St. Martin 65 on at
    RE: Web Service call overwrites CustomerKey

    Sorry, I did use Web Service code, not an XML query.  We did run the Web Services Config. Wizard and enabled the Company in question, and I had already used GetCompanyList to determine the company ID.  I'm also able to load up the SecurityConsole and view the policy settings.

  • Steve Kubis Profile Picture
    Steve Kubis on at
    RE: Web Service call overwrites CustomerKey

    A couple of thoughts...

    Did you use the Web Services Configuration Wizard to enable your company (37) to use web services?

    If you use the Security console, can you do things like look at policy settings for that company? The Security console uses the GP web service, so if it can't access information from the company with ID 37, there's no way that your application would either. That would indicate that the configuration for web services and that company aren't correct.

    You said you run a query to get the companies. Did you do this in the web service code? Your message doesn't say, but you might want to use the GetCompanyList method to retrieve the list of companies that are enabled for web services. If you don't see company 37 in the list, then that's your issue. Here's the link to GetCompanyList(). msdn.microsoft.com/.../cc508453.aspx

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans