I've been a .Net developer for some years now and quite a bit of experience connecting my ASP.Net and winform applications to web services. Recently I started working with Navision, specifically 2009 R2.
I have created a number of applications for ASP.Net and Winforms that connect to Navision's web services successfully and was recently asked to look into developing a Windows Phone 8.1 application to replace an existing application that runs on tablet pcs, and thats where its all gone horribly wrong...
After reading up and a few cases of trial and error, it seems that when I open Visual Studio 2013 and create a Windows Phone 8.1 Runtime application, it has no way of adding a Web Reference or Service Reference to the Navision Web Services.
I started again with w Windows Phone 8.1 (Silverlight) application and at least I get the option to add a Service Reference.
I added the Service Reference that point to my Web Service but the web service requires that the user set a set of credentials (a Windows Domain user account) and at no point was I prompted to enter these. Ok, maybe they're set at runtime...
After following a post in an Microsoft blog that covers connecting to Navision web services using Silverlight 3, I had most of my code in place, but there was still no option to enter any user credentials. It seems that there's a difference between regular Silverlight and the version used in the Windows Phone development environment.
The following code is a method taken from my test application...
protected void ConnectToNav()
{
try
{
string serviceURL = "http://192.168.0.50:7047/DynamicsNAV/WS/TestCompany/Page/svcUser";
svcUser_PortClient userService = new svcUser_PortClient("svcUser_Port", new EndpointAddress(serviceURL));
userService.ClientCredentials.UserName.UserName = @"Domain\User";
userService.ClientCredentials.UserName.Password = @"Password";
userService.ReadMultipleCompleted += delegate(object sender, ReadMultipleCompletedEventArgs e)
{
display(e.Error.Message);
if (e.Result.Length > 0)
{
display("10 Users:");
for (int i = 0; i < e.Result.Length; i++)
{
display(e.Result[i].ToString());
}
}
};
List<svcUser_Filter> filters = new List<svcUser_Filter>();
userService.ReadMultipleAsync(filters.ToArray(), null, 10);
}
catch (Exception ex)
{
display(ex.Message);
}
}
public void display(string s)
{
this.OutputTextBox.Text += s + Environment.NewLine;
}
and this is the error that gets returned...
The remote Server returned an unexpected response: (401) Unauthorized. In Silverlight, a 404 response code may be reported even when the service sends a difference error code.
I'd love to hear from anyone that has either got this working, or know of any good reference for this and how to get it working.
I would recommend using Windows Phone Runtime for easy of migration going forward. What you could do is use ASP.NET Web API and consume the NAV web service in that, while you then call the Web API from your Windows Phone app. Would this work for you?
Here's a good resource on ASP.NET Web API.