Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

c# - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...