Solved

.net call a webservice with credentials

Posted on 2010-11-19
5
959 Views
Last Modified: 2012-05-10
I have some code that calls a webservice on a different server.  I think the web service is java, but I don't know.  When the webservice has no authentication, it works.  When it does have authentication, I get a 501 error.

How can I call the web service with credentials?


SearchService svc = new global::Search.SearchService();
svc.Url = svcAddress;
SearchRequest req = new SearchRequest();
SearchResponse resp = svc.search(req); //this fails when pointing at a url that needs auth

Open in new window

0
Comment
Question by:jackjohnson44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 500 total points
ID: 34176776
What kind of authentication does the web service use? You need to find if it is java or .net.
If it is windows authentication, just use UseDefaultCredentials  property:
SearchService svc = new global::Search.SearchService();
svc.Url = svcAddress;
svc.UseDefaultCredentials  = true;

Check:
http://quickstart.developerfusion.co.uk/QuickStart/webservices/doc/UseDefaultCredentials.aspx
http://support.microsoft.com/kb/813834
0
 

Author Comment

by:jackjohnson44
ID: 34176908
I am not trying to pass default credentials, I am trying to pass credentials manually.  I believe it is java, but I can't figure it out, and there is no one to ask.

SearchService svc = new global::Search.SearchService();
svc.Credentials = new System.Net.NetworkCredential("user", "pass");
//If I DO NOT include the above line where I specify the credentials, I get this error
//The request failed with HTTP status 401: Unauthorized.

//If I DO include, I get this error
//The request failed with HTTP status 505: HTTP Version Not Supported.

svc.Url = svcAddress;
SearchRequest req = new SearchRequest();
SearchResponse resp = svc.search(req); //this fails when pointing at a url that needs auth
0
 

Author Comment

by:jackjohnson44
ID: 34176919
Also, if I go directly to the web service url in firefox, I get a login popup box.
0
 

Accepted Solution

by:
jackjohnson44 earned 0 total points
ID: 34222763
I solved it!

Add this line and it works:
svc.PreAuthenticate = true;
0
 

Author Closing Comment

by:jackjohnson44
ID: 34255738
It was svc.PreAuthenticate = true;
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question