使用Copy.CopyIntoItems Web服务将文件上载到SharePoint 2010时获取400错误请求

SharePoint新手。

我正在尝试使用Java的CopyIntoItems Web服务方法将文档上传到SharePoint,但继续获得400 Bad Request。 我使用Java的wsimport从.wsdl文件生成类文件。 这是我生成的类的Java代码。

public static void createDocument(CopySoap port) { String url = SoapPortProvider.spSiteUrl + "/Shared Documents/Temp Folder/test.txt"; String sourceUrl = "http://null"; byte[] content = IoUtil.getBytes(new File("C:/CopyFile/READ-ME.txt")); FieldInformation descInfo = new FieldInformation (); descInfo.setDisplayName("Test Doc"); descInfo.setType(FieldType.TEXT); descInfo.setValue("Test uploaded file"); DestinationUrlCollection urls = new DestinationUrlCollection(); urls.getString().add(url); FieldInformationCollection infos = new FieldInformationCollection (); infos.getFieldInformation().add(descInfo); CopyResultCollection results = new CopyResultCollection (); Holder resultHolder = new Holder(results); Holder longHolder = new Holder(new Long(-1)); port.copyIntoItems(sourceUrl, urls, infos, content, longHolder, resultHolder); } 

我的SOAP请求看起来像

     http://null  https://www.mysite.com/sites/TestSite/Shared Documents/Temp Folder/test.txt     KioqTWFrZSBzdXJlIHRoZSBjb==    

而我得到的回应是

 null: HTTP/1.1 400 Bad Request Content-length: 0 X-powered-by: ASP.NET Server: Microsoft-IIS/7.5 Date: Tue, 14 Feb 2012 16:29:51 GMT Microsoftsharepointteamservices: 14.0.0.5138 

这对我来说并不多。 可能会遗漏什么?

我已经使用以下代码完美地为我工作:

  try { //Copy WebService Settings string webUrl = "http://sharepointportal.ABC.com/"; WSCopy.Copy copyService = new WSCopy.Copy(); copyService.Url = webUrl + "/_vti_bin/copy.asmx"; copyService.Credentials = new NetworkCredential("username", "****", "Domain"); //Declare and initiates the Copy WebService members for uploading string sourceUrl = "C:\\Work\\Ticket.Doc"; //Change file name if not exist then create new one string[] destinationUrl = { "http://sharepointportal.ABC.com/personal/username/Document Upload/Testing Document/newUpload.Doc" }; WSCopy.CopyResult cResult1 = new WSCopy.CopyResult(); WSCopy.CopyResult cResult2 = new WSCopy.CopyResult(); WSCopy.CopyResult[] cResultArray = { cResult1, cResult2 }; WSCopy.FieldInformation fFiledInfo = new WSCopy.FieldInformation(); fFiledInfo.DisplayName = "Description"; fFiledInfo.Type = WSCopy.FieldType.Text; fFiledInfo.Value = "Ticket"; WSCopy.FieldInformation[] fFiledInfoArray = { fFiledInfo }; FileStream strm = new FileStream(sourceUrl, FileMode.Open, FileAccess.Read); byte[] fileContents = new Byte[strm.Length]; byte[] r = new Byte[strm.Length]; int ia = strm.Read(fileContents, 0, Convert.ToInt32(strm.Length)); strm.Close(); //Copy the document from Local to SharePoint uint copyresult = copyService.CopyIntoItems(sourceUrl, destinationUrl, fFiledInfoArray, fileContents, out cResultArray); MessageBox.Show("Suceess"); } catch (Exception ex) { MessageBox.Show(ex.Message); } 

得到它了! 初始化时我的代码中只有一个错误。 以下是希望使用SharePoint和Java的任何人的工作代码。 我使用JAX-WS wsimport工具从.wsdl文件生成类文件。 您可以将工具直接指向WSDL的URL,例如, https://my.site.come/sites/mysite/_vti_bin/copy.asmx?wsdl

 public static CopySoap getPort(String username, String password) { Copy service = new Copy(); CopySoap port = service.getCopySoap(); BindingProvider bp = (BindingProvider) port; bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://my.site.com/sites/mysite/_vti_bin/copy.asmx"); return port; } public static void createDocument(CopySoap port) { String url = "https://my.site.com/sites/mysite/Shared Documents/Temp Folder/test.txt"; String sourceUrl = "C:\\CopyFile\\READ-ME.txt"; DestinationUrlCollection urls = new DestinationUrlCollection(); urls.getString().add(url); byte[] content = IoUtil.getBytes(new File(sourceUrl)); FieldInformation titleInfo = new FieldInformation (); titleInfo.setDisplayName("Title"); titleInfo.setType(FieldType.TEXT); titleInfo.setValue("Test Doc"); FieldInformationCollection infos = new FieldInformationCollection (); infos.getFieldInformation().add(titleInfo); CopyResultCollection results = new CopyResultCollection (); Holder resultHolder = new Holder(results); Holder longHolder = new Holder(new Long(-1)); port.copyIntoItems(sourceUrl, urls, infos, content, longHolder, resultHolder); }