Using Nav 2009 SP1 web service from a mobile device

GrahamHutchinsonGrahamHutchinson Member Posts: 4
edited 2009-10-07 in NAV Three Tier
Does anybody have a C# example of using a Nav 2009 Web Service from a mobile device,without using Dynamics Mobile (Which has been discontinued) ?

I am having a problem with setting credentials to use the service.

Comments

  • tlarsontlarson Member Posts: 27
    Start off by reviewing this: http://dynamicsuser.net/blogs/navdev/ar ... rvice.aspx. It shows the general case for how to consume a Nav 2009 web service from C#.

    The question you seem to be focusing on is with authentication to the web service - I'm guessing you're getting a HTTP 401 unauthorized error, or something similar.

    There are two options here:

    1. Set your C# application to run in the context of the user that has permissions on the web service, then use the
    NavWebService.usedefaultcredentials = true;
    
    setting shown in the article referenced above.

    However, if you're running on a mobile device, #1 could be tricky. So let's look at option #2

    2. Get rid of
    NavWebService.UseDefaultCredentials = true;
    
    and use this in its place:
    NavWebService.UseDefaultCredentials = false;
    NavWebService.Credentials = new NetworkCredential("myUsername", "myPassword");
    

    I think the NetworkCredential constructor also takes your domain name as a third parameter if needed.

    Tim Larson
  • GrahamHutchinsonGrahamHutchinson Member Posts: 4
    Thanks for that Tim

    I have tried doing what you suggested, but I am still unable to get a connection.

    I am using the following code extracted from Lars Lohndorf-Larsen's example
    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Reflection;
    using System.Net;
    
    namespace SmartDeviceProjectLars
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                WS.web NAVWebService = new WS.web();
    
                NAVWebService.Credentials = new NetworkCredential("Name", "Pass");
    
                textBox2.Text = NAVWebService.AddX(textBox1.Text);
    
    
    
            }
        }
    }
    

    Because it is a smart device project "NavWebService.UseDefaultCredentials = false" is not available.

    I have used the identical code in a windows application and it works perfectly.

    Any other suggestions?
  • GrahamHutchinsonGrahamHutchinson Member Posts: 4
    I was using an emulator from visual studio to test this.
    I have since copied the exe file to a mobile device and it is now working OK

    Thanks for your help

    Graham
Sign In or Register to comment.