Bug 4255 - 401 Unauthorized Error an access to Web Service
Summary: 401 Unauthorized Error an access to Web Service
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Martin Baulig
Depends on:
Reported: 2012-04-05 06:59 UTC by Martin Stecher
Modified: 2018-02-20 11:04 UTC (History)
7 users (show)

Tags: XATriaged
Is this bug a regression?: ---
Last known good build:

Project wich reproduces the error (28.55 KB, application/x-zip-compressed)
2012-04-05 06:59 UTC, Martin Stecher

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 4255 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Martin Stecher 2012-04-05 06:59:40 UTC
Created attachment 1624 [details]
Project wich reproduces the error


i'm having trouble with the SOAP use... I am accessing the webservice on the usual way and use SOAP to read the information out of the WebService provided by Microsoft DynamicsNAV. In WindowsForms the Code works properly, but on the phone it won't...

Have a look on the project i set up. The problem is, i've the service only on Intranet...
Comment 1 Martin Stecher 2012-04-05 08:00:47 UTC
Additional i can say, if i use NetworkCredential i have a BasicAuthentification request. But i would need NTLM, so i use the CredentialCache and try it. I i do so, so i get a Soap-Header like this: 

User-Agent: Mono Web Services Client Protocol 4.0.50524.0
SOAPAction: "urn:microsoft-dynamics-schemas/codeunit/Test:Authentication"
Content-Type: text/xml; charset=utf-8
Content-Length: 356
Expect: 100-continue
Connection: keep-alive

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><Authentication xmlns="urn:microsoft-dynamics-schemas/codeunit/Test"><username /><password /></Authentication></soap:Body></soap:Envelope>
Comment 2 Martin Baulig 2012-09-19 01:15:25 UTC
This could be related to #4993.
Comment 3 Marek Habersack 2016-09-01 19:51:18 UTC
@Martin, any update?
Comment 4 Fernando 2018-02-20 10:50:26 UTC
@Martin, I have the same issue. Did you find some solution?
Comment 5 Martin Stecher 2018-02-20 11:04:15 UTC
I ended up using a workaround for android (i ended up using it for silverlight too) using BasicHttpBinding in my case. using this you are able to authenticate using NTLM and can consume the web service with ease.

like this:

BasicHttpBinding binding = new BasicHttpBinding();
binding.Name = "Nav Binding";
binding.AllowCookies = true;

binding.MaxBufferSize = int.MaxValue;

binding.MaxReceivedMessageSize = int.MaxValue;

binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.MaxReceivedMessageSize = int.MaxValue;
binding.SendTimeout = new TimeSpan(0, 10, 0);
binding.ReceiveTimeout = new TimeSpan(0, 10, 0);

instance = new PortClient(binding, new EndpointAddress(NavServices.BaseUri.AbsoluteUri));

var nc = new NetworkCredential
				 Domain = NavServices.Domain,
				 UserName = NavServices.User,
				 Password = NavServices.Password

instance.ClientCredentials.Windows.ClientCredential = nc;
instance.ClientCredentials.Windows.AllowedImpersonationLevel =