Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How add service reference in visual studio 2008 authenticating against password-protected web service

I want to reference a web service, and it requires user/pass authentication. In VS 2008, if I try to "add reference", or "add service reference", all I can type is the URL, there's no way to input my credentials. Obviously, if I try to load the ws, it shows me a nice message:

The request failed with HTTP status 403: Forbidden. Metadata contains a reference that cannot be resolved: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm="weblogic"'. The remote server returned an error: (401) Unauthorized.

So my question is: Is it possible (using VS 2008) to add a reference to a web service that is protected? How?

like image 756
ditto1977 Avatar asked Apr 08 '10 21:04

ditto1977


People also ask

How do I add a website reference in Visual Studio 2008?

To correct this, right click on References and choose Add Service Reference. In the next window, click on the Advanced button in the lower left. In the next window, click Add Web Reference in the lower left. Enter a name, then you can use the WSDL URL.

How do I add a Web service reference in Visual Studio?

You can also open the Add Web Reference dialog box in the Solution Explorer pane by right-clicking References and selecting Add Web Reference. In the Web reference name box, rename the Web reference toExcelWebService. Click Add Reference to add a Web reference for the target Web service.


1 Answers

It sounds like you're trying to use a Web Reference, and not a Service Reference (although I believe a Web Reference is a one kind of Service Reference). In VS08, after you have launched the "Add Service Reference", typed the URL to the web service, click the "Advanced" button, then click the "Add Web Reference". Type the URL again, then click "Add Web Reference". Now you should have a web reference instead, then authentication is similar to below:

WebService.Service myService = new WebService.Service();
myService.Credentials = new System.Net.NetworkCredential("username", "password");
WebService.ResultType results = myService.MyMethodReturnsResultType();
like image 69
Erik Philips Avatar answered Sep 18 '22 17:09

Erik Philips