Options

Web Service & Bindingsources

JDVyskaJDVyska Member Posts: 179
edited 2009-07-13 in NAV Three Tier
So, I'm in the very early crawl stages of understanding Web Services. I've been reading the MSDN examples and working forward from there. If there are other sources of knowledge for this stage, please, link them.

Here's where I'm at and trying to understand how to move forward from.

I'm using Visual Studio 2010 (beta). I've added a Web Reference to a Customer Page that I've published. Using some of the automatic tricks of VS2010, I've a nice detail form that shows all the fields from the Customer table. This was accomplished via:
  1. Add Web Reference (let's call it CustomerPageService)
  2. Showing my Data Sources
  3. Setting the Customer object of the CustomerPageService to be a Detail view
  4. Dragged the Customer data source to my form designer. It adds all the fields from Customer to the form, as well as a basic Navigation Menu

However, inside of my network, where I am using windows authentication and can access the Page URL without login verification, it does not retrieve any data.

My assumption at this stage is that something is wrong with my auto-generated customerBindingSource: namely, that it's having some issue behind the scenes with authorization.

To verify this, I put in some very simple code before the InitializeComponents:
Customer_Service test = new Customer_Service();

            // Create filter for searching for customers
            List<Customer_Filter> filterArray = new List<Customer_Filter>();
            Customer_Filter nameFilter = new Customer_Filter();
            nameFilter.Field = Customer_Fields.No;
            nameFilter.Criteria = "C*";
            filterArray.Add(nameFilter);

            _CustomerArray = test.ReadMultiple(filterArray.ToArray(),null,100);
            foreach (Customer c in _CustomerArray)
            {
                _CustomerList.Add(c);
            }

            MessageBox.Show("" + _CustomerList.Count);

When I run this code, I get a HTTP 401: Unauthorized. To test it one stage further, I altered:
Customer_Service test = new Customer_Service();
to something like (login info changed):
Customer_Service test = new Customer_Service();
            test.UseDefaultCredentials = false;
            test.Credentials = new System.Net.NetworkCredential("User", "Password", "DOMAIN");

After running that code, I get my expected message box of CustomerList.Count.


My question, then, is: How can I set the auto-generated BindingSource that VS2010 produces from my Web Reference to the service to use different Credentials? I've dug around in my 'Form1.Designer.cs' to see if there is any logical place that the Service is called explicitly, but it's rather complicated code.


(No, I don't expect I'll be able to make my way in the world with Web Services using Drag-N-Drop programming, but I'd love to be able to use *some* of that functionality in VS2010 using a NAVWebService -- even if the "right way" is something like writing a custom BindingSource class for it.)
JEREMY VYSKA
CEO, Spare Brained Ideas, Göteborg, Sweden
New (April 2021) Getting Started with Microsoft Dynamics 365 Business Central Book Available: "Your First 20 Hours with Business Central"

Answers

  • Options
    JDVyskaJDVyska Member Posts: 179
    So, of course, AFTER I figured it out, I found this post.

    Basically, after the InitializeComponents was called, I then have this chunk'o'code:
    Customer_Service CustServ = new Customer_Service();
                CustServ.UseDefaultCredentials = false;
                CustServ.Credentials = new System.Net.NetworkCredential(user, pass, domain);
    
                // Create filter for searching for customers
                filterArray.Clear();
                Customer_Filter nameFilter = new Customer_Filter();
                nameFilter.Field = Customer_Fields.No;
                nameFilter.Criteria = "*";
                filterArray.Add(nameFilter);
                customerBindingSource.DataSource = CustServ.ReadMultiple(filterArray.ToArray(), null, 0);
    

    That really was all there was to it.
    ](*,) & \:D/
    JEREMY VYSKA
    CEO, Spare Brained Ideas, Göteborg, Sweden
    New (April 2021) Getting Started with Microsoft Dynamics 365 Business Central Book Available: "Your First 20 Hours with Business Central"
Sign In or Register to comment.