Solved

.net call a webservice with credentials

Posted on 2010-11-19
5
951 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I solved it!

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

Author Closing Comment

by:jackjohnson44
Comment Utility
It was svc.PreAuthenticate = true;
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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.…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

772 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now