SharePoint CopyIntoItems SOAP message in Objective

2019-08-31 07:46发布

问题:

I'm trying to upload a file to SharePoint programmatically via a Mac Application that I am currently writing. I can use the GetListItems webservice to retrieve a list of files, and all authentication etc works correctly. I form the SOAP message myself as follows:

At first I thought I just had the Objective C side written incorrectly, but I've been using the HTTP request extension for Firefox, 'Poster', and still can't get it to work.

The soap message in Poster that I construct is:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
xmlns:xsd="http://www.w3.org/2001/XMLSchema"     
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <CopyIntoItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <SourceUrl>http://null</SourceUrl>
      <DestinationUrls>
        <string>myurl.com/Shared Documents/Documents/TestingFile.txt</string>
      </DestinationUrls>
      <Stream>VGVzdGluZyB0ZXN0aW5n</Stream>
    </CopyIntoItems>
  </soap:Body>
</soap:Envelope>

The stream (at the moment) is just some data, to see if I can get it to work. I read that setting the SourceUrl as http://null, can help in some instances. I also read that the DestinationURL needs to be the full path. The problem here is:

1) If I put the URL without https:// then I get a response of:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope     
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CopyIntoItemsResponse 
xmlns="http://schemas.microsoft.com/sharepoint/soap/">    
<CopyIntoItemsResult>0</CopyIntoItemsResult><Results><CopyResult ErrorCode="Success" 
DestinationUrl="myurl.com/Shared Documents/Documents/TestingFile.txt" /></Results>
</CopyIntoItemsResponse></soap:Body></soap:Envelope>

2) If I put the full path, e.g.

https://myurl.com/Shared Documents/Documents/TestingFile.txt

then the result tells me the same as before, except for this bit:

<CopyResult ErrorCode="Unknown" ErrorMessage="Object reference not set to an instance of an     
object."     
DestinationUrl="https://dbp.btfinancialgroup.com/Shared%20Documents/Papers/TestingFile.txt" 
/>

3) If I put the full path, in quotes, e.g.

"https://myurl.com/Shared Documents/Documents/TestingFile.txt"

then the results tell me the same as the first, e.g. that it was successful, but with a destinationURL of this:

DestinationUrl="&quot;https://dbp.btfinancialgroup.com/Shared 
Documents/Papers/TestingFile.txt&quot;"

In ALL of these scenarios, the file does not exist in the destination at the end of the request.

I'm really stuck, as most online suggestions are for remedying C# problems, which use the .net protocols for connecting to SharePoint.

Any suggestions?

Thanks

回答1:

To assist in anyone else who may come across this problem.

It turned out not to be an issue with my code at all, which I established by making a C# project to try and use the better connectivity it provides to SharePoint, and also spoke to someone in Microsoft Support who confirmed my code should work.

In the end, it was incorrect mappings on the server, which meant the web service never linked correctly to the URLs. This caused the "Object reference not set to an instance of an object" error.

To anyone else receiving this error message, it may not lie just in a problem with the values you are passing to the web service - also check the mappings set up on the server. Apparently the ULS logs may help with this, the Microsoft support guy mentioned, in terms of narrowing down what's causing it.