The request failed with HTTP status 401: Unauthori

2019-10-06 14:20发布

问题:

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.

回答1:

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.