简体   繁体   中英

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.

URL: 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.

The above URL is working in the browser.

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. It will behave as normal dll or any other reference. create instance of service reference name then use the instance to call which ever method from your web service with parameters if parameters exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM