Solved

.net call a webservice with credentials

Posted on 2010-11-19
5
954 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
  • 4
5 Comments
 
LVL 35

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

810 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