Save File to Sharepoint Server using JAX-WS

Posted by Evan Porter on Stack Overflow See other posts from Stack Overflow or by Evan Porter
Published on 2011-02-25T14:55:12Z Indexed on 2011/02/27 23:25 UTC
Read the original article Hit count: 400

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about java

Related posts about sharepoint