Link to home
Start Free TrialLog in
Avatar of gillgates
gillgates

asked on

Java equivalent to .NET's "System.Net.CredentialCache.DefaultCredentials"

Here is the code in C# which works

<Begin C# Code>
Webs.Webs x = new Webs.Webs();
x.PreAuthenticate = true;
x.Credentials = System.Net.CredentialCache.DefaultCredentials;
x.Url = url + @"/_vti_bin/webs.asmx";
System.Xml.XmlNode n = x.GetWebCollection();
<End C# Code>

However I would like to access this SharePoint webservice from a java application.  How do I replicate the "System.Net.CredentialCache.DefaultCredentials" in java?


Here is my Java code but I get a "(401)Unauthorized" error which I also get in the .NET code if I don't do the "x.Credentials = System.Net.CredentialCache.DefaultCredentials" call.

I used wsdl2java to bring the webservice into eclipse (http://wsdl2javawizard.sourceforge.net/)

<Begin Java Code>
try
{
     _GetWebCollection parameters = new _GetWebCollection();
     WebsLocator w = new WebsLocator();
     WebsSoap ws = w.getWebsSoap();
     ws.getWebCollection(parameters);
}
catch (ServiceException e)
{
     e.printStackTrace();
}
catch (RemoteException e)
{
     e.printStackTrace();
}
ASKER CERTIFIED SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial