question

HungMelvinMC-3815 avatar image
0 Votes"
HungMelvinMC-3815 asked BakerKong-MSFT commented

Error - 401 Unauthorized when calling SharePoint webservice

Our problem – Website returns HTTP status 401. We checked user account it is valid.

The related details are listed as follows:

With “Domain” is work in previous UAT environment. And now we can’t (we need to remove the “Domain” in “NetworkCreadential“ method).
With “Domain” is work in PDN environment.
“DefaultNetworkCredentials” or “DefaultCredentials” or "System.Net.CredentialCache.DefaultCredentials" is doesn’t work in UAT environment (Throw Error: The request failed with HTTP status 401: Unauthorized).

I have tried restarting both IIS and the application pool but this does not help.
IIS Setting:

Anonymous Authentication is Enabled
Windows Authentication is Enabled
Authorization Rules is set up to Allow All Users
In the IIS log I can see the following:
2020-07-08 08:05:09 POST /_vti_bin/Lists.asmx - 80 0#.w|asia2\xxxx Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.36543) 200 0 0 62
2020-07-08 08:06:19 GET /sites/intranet/TC/_vti_bin/Lists.asmx - 80 - Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+6.1;+WOW64;+Trident/5.0;+SLCC2;+.NET+CLR+2.0.50727;+.NET+CLR+3.5.30729;+.NET+CLR+3.0.30729;+InfoPath.3;+.NET4.0C;+.NET4.0E) 401 1 2148074254 0

office-sharepoint-server-development
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TKujala avatar image
0 Votes"
TKujala answered HungMelvinMC-3815 commented
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi TKujala,

Someone told me, This “SharePoint 2013 - General Discussions and Questions” Forum will be migrating to a new home on Microsoft Q&A, please refer to this sticky post for more details.

0 Votes 0 ·
TKujala avatar image
0 Votes"
TKujala answered

@HungMelvinMC-3815,


Okay.


I hope you will get an answer to your question.


Have a nice day.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

BakerKong-MSFT avatar image
0 Votes"
BakerKong-MSFT answered BakerKong-MSFT commented

Hi HungMelvinMC-3815,

Could you please more info regarding this issue? Can i know the goal and what about the background info? Which version SharePoint you're using? It would be appreciated if we can reproduce the issue.

Thanks
Baker Kong

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Baker,

When i calling SharePoint web service via .Net client program, and i got the error message "The request failed with HTTP status 401: Unauthorized."

The user should be Local Administrator and Site Collection Admin.

My Code sample (with Domain it is not working):
WebService_as2hkdiis11.Lists client = new WebService_as2hkdiis11.Lists();
client.Credentials = new NetworkCredential("xxxxxx", "xxxxx", "ASIA2");
client.Url = "http://as2hkdiis11/sites/Legal_and_Compl/_vti_bin/Lists.asmx";

SharePoint Version: 2013 (15.0.4631.1001)

0 Votes 0 ·

Hi HungMelvinMC-3815,

I tested you code in a console app on my SP 2013, add .asmx to web reference. And initalize the client with below code:

 WebService_as2hkdiis11.Lists client = new WebService_as2hkdiis11.Lists();
 client.Credentials = new NetworkCredential("contoso\\Administrator", password);
 client.Url = "http://site/_vti_bin/Lists.asmx";

Or

 WebService_as2hkdiis11.Lists client = new WebService_as2hkdiis11.Lists();
 client.Credentials = new NetworkCredential("Administrator", password,"contoso");
 client.Url = "http://site/_vti_bin/Lists.asmx";

Both works well here. May i know what's the meaning of "with Domain it is not working (we need to remove the “Domain” in “NetworkCreadential“ method)"?


Best Regards,
Baker Kong

0 Votes 0 ·