The request failed with HTTP status 401: Unauthorized

大兔子大兔子 提交于 2019-12-04 23:38:38
btlog

You need to set the credentials in you application when you initialise the webService object.

Something like webService.UseDefaultCredentials = true

This will set the credentials of the request to the current user executing the application.

In IIS 7, enable anonymous authentication and you should be able to debug.

user1772100
webService.UseDefaultCredentials = true

This worked for me.

you can use this:

webservice.UseDefaultCredentials = true;

if does not work, use the below code instead of the code above

webservice.Credentials = new NetworkCredential("userName", "password", "domain");
webservice.PreAuthenticate = true;

note: the username Password and domain is the user credential of the user that access to webservice

so make sure that user have permission to access to web service

maybe the user is the windows user

and you can get the domain from: right click in "MyComputer" and properties the domain is the Computer name or Workgroup

ali

im am test this way:

CheckListService.CheckList chkSrvice = new CheckListService.CheckList() {
    UseDefaultCredentials = true };
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!