Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save File to Sharepoint Server using JAX-WS

I'm trying to save a file to a Sharepoint server using JAX-WS. The web service call is reporting a success, but the file doesn't show up.

I used this command (from a WinXP) to generate the Java code to make the JAX-WS call:

wsimport -keep -extension -Xnocompile http://hostname/sites/teamname/_vti_bin/Copy.asmx?WSDL

I get a handle on the web service which I called port using the following: CopySoap port = null;

if (userName != null && password != null) {
    Copy service = new Copy();
    port = service.getCopySoap();
    ((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
    ((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
} else {
    throw new Exception("Holy Frijolé! Null userName and/or password!");
}

I called the web service using the following:

port.copyIntoItems(sourceUrl, destUrlCollection, fields ,
    "Contents of the file".getBytes(), 
    copyIntoItemsResult, copyResultCollection)

The sourceUrl and the only url in destUrlCollection equals "hostname/sites/teamname/Tech Docs/Sub Folder".

The FieldInformationCollection object named fields contains only one FieldInformation. The FieldInformation object has "HelloWorld.txt" as the value for displayName, internalName and value. The type property is set to FieldType.FILE. The id property is set to (java.util.UUID.randomUUID()).toString().

The call to copyIntoItems returns successfuly; copyIntoItemsResult contains a value of 0 and the only CopyResult object set in copyResultCollection has an error code of "SUCCESS" with a null error message.

When I look into the "Tech Docs" library on Sharepoint, in the "Sub Folder" there's no file there.

Why wouldn't it tell me what I did wrong? Did I just miss a step?

Update (Feb 26th, 2011)

I've changed my FieldInformation object's displayName and internalName properties to be "Title" as suggested. Still no joy, but a step in the right direction.

After playing around with the urls for a bit, I got these results:

With both the sourceUrl and the only destination URL equivalent, with no protocol, I get the SUCCESS response but no actual document appears in the document library.

With both of the URLs equivalent but with an "http://" protocol specified, I get an UNKNOWN error with "Object reference not set to an instance of an object." as the message.

With the source URL an empty string or null, I get an UNKNOWN error with " Value does not fall within the expected range." as the error message.

Update (March 2nd, 2011)

As suggested by Alexei Levenkov, I used Fiddler to see what was going on and found this:

#   Result  Protocol    Host    URL Body    Caching Content-Type    Process Comments    Custom  
34  401 HTTP    hostname    /sites/teamname/_vti_bin/Copy.asmx?WSDL 1,656       text/html   javaw:5304          
35  401 HTTP    hostname    /sites/teamname/_vti_bin/Copy.asmx?WSDL 1,539       text/html   javaw:5304          
36  200 HTTP    hostname    /sites/teamname/_vti_bin/Copy.asmx?WSDL 10,887  private     text/xml; charset=utf-8 javaw:5304          
37  401 HTTP    hostname    /sites/teamname/_vti_bin/Copy.asmx  1,656       text/html   javaw:5304          
38  401 HTTP    hostname    /sites/teamname/_vti_bin/Copy.asmx  1,539       text/html   javaw:5304          
39  200 HTTP    hostname    /sites/teamname/_vti_bin/Copy.asmx  611 private, max-age=0      text/xml; charset=utf-8 javaw:5304          

It looks like a simple handshake going on until it gets the HTTP 200 for both the WSDL and the web service call.

So I tried not putting my username and password in the RequestContext and I get a similar thing as I do above for the WSDL request (two HTTP 401s and one HTTP 200), but the WebService call only has one HTTP 200. If it no longer uses my username/password, then it should theoretically fail authentication.

like image 503
Evan Porter Avatar asked Feb 25 '11 14:02

Evan Porter


2 Answers

Destination Urls should contain full paths to files. I check out sample on method description page - http://msdn.microsoft.com/en-us/library/copy.copy.copyintoitems.aspx.

like image 89
Alexei Levenkov Avatar answered Nov 15 '22 17:11

Alexei Levenkov


Your issue is probably the fields.

DisplayName and InternalName want to be "Title", and the value be HelloWorld.txt

Also, leave ID empty, SharePoint will populate that.

like image 33
James Love Avatar answered Nov 15 '22 17:11

James Love