简体   繁体   English

请求失败,HTTP 状态为 401:调用 Web 服务时未经授权

[英]The request failed with HTTP status 401: Unauthorized while calling web service

I have URL of web service and I am trying to call that web service in my WebAPI project.我有 Web 服务的 URL,我试图在我的 WebAPI 项目中调用该 Web 服务。

URL: http://domain/soap/wsdl11?services=XYZ_Service&sap-client=007&sap-user=demo&sap-password=demo@123网址: http://domain/soap/wsdl11?services=XYZ_Service&sap-client=007&sap-user=demo&sap-password=demo@123

The code that I have tried:我试过的代码:

Service.DemoService client = new Service.DemoService();
client.Credentials = new NetworkCredential("demo", "demo@123", "domain");
client.PreAuthenticate = true;
client.GetData("Test");

But its showing:但它的显示:

The request failed with HTTP status 401: Unauthorized.请求失败,HTTP 状态为 401:未经授权。

The above URL is working in the browser.上面的 URL 在浏览器中有效。

You can use service reference in you application.您可以在应用程序中使用服务引用。 Right click references click to Add Service Reference popup will appear where you can add your web service URL(without method and parameters) by give the service reference with name.右键单击引用单击以添加服务引用弹出窗口将出现,您可以通过给服务引用名称添加您的 Web 服务 URL(不带方法和参数)。 It will behave as normal dll or any other reference.它将表现为正常的 dll 或任何其他引用。 create instance of service reference name then use the instance to call which ever method from your web service with parameters if parameters exist.创建服务引用名称的实例,然后使用该实例从带有参数的 Web 服务调用任何方法(如果存在参数)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 请求失败,HTTP状态为401:未经授权 - The request failed with HTTP status 401: Unauthorized 错误请求失败,HTTP状态为401:未经授权 - Error The request failed with HTTP status 401: Unauthorized 请求失败,HTTP 状态为 401:未授权 IN SSRS - The request failed with HTTP status 401: Unauthorized IN SSRS 请求失败,HTTP状态为401:未授权。 - The request failed with HTTP status 401: Unauthorized. 请求失败,HTTP状态为401:未授权 - IIS升级 - WebService和Web应用程序 - The request failed with HTTP status 401: Unauthorized - IIS Upgrade - WebService & Web Application 请求失败,HTTP状态为401:再次尝试未授权 - Request failed with HTTP status 401: Unauthorized on second try 请求失败,HTTP 状态为 401:已授权从 C# asp.net 访问 sharepoint Web 服务 - The request failed with HTTP status 401: authorized for access sharepoint web service from C# asp.net 调用 SAP PI Web 服务时,HTTP 请求未经客户端身份验证方案“Ntlm”授权 - The HTTP request is unauthorized with client authentication scheme 'Ntlm' while calling SAP PI web service 服务器无法处理请求。 --->请求失败,HTTP状态为401:未经授权 - Server was unable to process request. ---> The request failed with HTTP status 401: Unauthorized 在C#窗口应用程序中SSRS报告呈现中出现错误:请求失败,HTTP状态为401:未经授权 - Getting Error in SSRS report rendering in C# window application: The request failed with HTTP status 401: Unauthorized
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM