title: Save File to Sharepoint Server using JAX-WS
body: <p>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.</p>
  
  <p>I used this command (from a WinXP) to generate the Java code to make the JAX-WS call:</p>
  
  <pre><code>wsimport -keep -extension -Xnocompile http://hostname/sites/teamname/_vti_bin/Copy.asmx?WSDL
  </code></pre>
  
  <p>I get a handle on the web service which I called <code>port</code> using the following:
  CopySoap port = null;</p>
  
  <pre><code>if (userName != null &amp;&amp; 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!");
  }
  </code></pre>
  
  <p>I called the web service using the following:</p>
  
  <pre><code>port.copyIntoItems(sourceUrl, destUrlCollection, fields ,
      "Contents of the file".getBytes(), 
      copyIntoItemsResult, copyResultCollection)
  </code></pre>
  
  <p>The <code>sourceUrl</code> and the only url in <code>destUrlCollection</code> equals "hostname/sites/teamname/Tech Docs/Sub Folder".</p>
  
  <p>The <code>FieldInformationCollection</code> object named <code>fields</code> contains only one <code>FieldInformation</code>. 
  The <code>FieldInformation</code> object has "HelloWorld.txt" as the value for displayName, internalName and value.
  The type property is set to <code>FieldType.FILE</code>. The id property is set to <code>(java.util.UUID.randomUUID()).toString()</code>.</p>
  
  <p>The call to <code>copyIntoItems</code> returns successfuly; <code>copyIntoItemsResult</code> contains a value of 0 and the only <code>CopyResult</code> object
  set in <code>copyResultCollection</code> has an error code of "SUCCESS" with a null error message.</p>
  
  <p>When I look into the "Tech Docs" library on Sharepoint, in the "Sub Folder" there's no file there.</p>
  
  <p>Why wouldn't it tell me what I did wrong? Did I just miss a step?</p>
  
  <p><strong>Update (Feb 26th, 2011)</strong></p>
  
  <p>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.</p>
  
  <p>After playing around with the urls for a bit, I got these results:</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>With the source URL an empty string or <code>null</code>, I get an UNKNOWN error with " Value does not fall within the expected range." as the error message.</p>
  
  <p><strong>Update (March 2nd, 2011)</strong></p>
  
  <p>As suggested by Alexei Levenkov, I used Fiddler to see what was going on and found this:</p>
  
  <pre><code>#   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          
  </code></pre>
  
  <p>It looks like a simple handshake going on until it gets the HTTP 200 for both the WSDL and the web service call.</p>
  
  <p>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.</p>