This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Trying to get a sharepoint webservice talking to code has left me clueless after a few days of searching on the web and trying many examples from blogs.
I'm using wsdl2java to create the code from the locally copied WSDL but I'm running into the dreaded 401 error after trying numerous approaches.
The code below is where I advanced the most, I can successfully get the WSDL which also requires NTLM etc, but what do to do afterwards is unclear to me.
This is the code I have so far:
// Enable logging
//The above outputs all the happy talk between code & sharepoint server
// Update this to the actual URL
String url = "http://sharepointhost/WebForms/_vti_bin/lists.asmx?wsdl"; //I use this in a method to get the response back
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);
HostConfiguration hostConfig= client.getHostConfiguration();
// Authenticate using NTLM
client.getState().setCredentials("domainname", "sharepointhost", new NTCredentials("user1","passwd1","","DOMAIN"));
int statusCode = client.executeMethod(method);
System.out.println("Stat=" +HttpStatus.getStatusText(statusCode)); //This returns OK to systemout
String strOutput = method.getResponseBodyAsString(); //This returns the WSDL
//The output so far shows that NTLM auth has been done, and the wsdl output is returned
//Next lines are where it's becoming blurry for me on how to continue using that webservice.
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
List authPrefs = new ArrayList (1);
ListsSoapStub lists = new ListsSoapStub();
lists._setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); //This doesn't seem the right way to do it?
GetListCollectionResponseGetListCollectionResult res = lists.getListCollection(); //and here it's not authenticated
In this example I get a no endpoint set error, but in some other tries/approaches I managed to get the endpoint set only to have it complain with the 401 unauthorized error.
Any help is more then appreciated, this problem is doing in my head, I thought consuming a sharepoint webservice would be a little more straightforward
Joined: Nov 30, 2010
I got it working, with only the help from God-of-Google and way too much persistence, pure endorphins overflow now. damn, I'm happy!
For those stuck with the same problem, code below works.
I generated the java code with axis2 1.5.1 & options "wsdl2java -uri wsdl.wsdl -s -ssi -s -f