我正在使用Java(1.7)开发自定义组件。 此组件需要能够将文件推送和拉出到SharePoint 2010 Server。
我已成功将文件与元数据一起推送到服务器。 我还成功地从服务器中拉出了一个文件。
我需要能够根据用户为我的组件提供的内容,根据不同的搜索条件搜索(查询)服务器。
我无法成功连接到SPSearch Web服务。
我收到此错误:
“在main中捕获到错误:javax.xml.ws.WebServiceException:{http://microsoft.com/webservices/SharePoint/QueryService} QueryServiceSoap不是有效服务。有效服务包括:{http://schemas.microsoft.com/sharepoint/soap/}列表 “
我在Google上无休止地搜索了一些C#代码,我能够自己教会我如何使用该服务,但它无法帮助我成功使用该服务。我找不到一个好的Java参考来使用这个Web服务。
非常感谢任何帮助或建议。谢谢。
(wsdl = SPURL / _vti_bin / spsearch.asmx?wsdl; endpoint = SPURL / _vti_bin / spsearch.asmx)
以下是代码:
protected ListsSoap getListsSoap(String username, String password, String wsdl, String endpoint) throws Exception {
System.out.println("Creating a ListsSoap instance...");
Lists service = new Lists(new URL(wsdl), new QName("http://schemas.microsoft.com/sharepoint/soap/", "Lists"));
ListsSoap port = service.getListsSoap();
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, endpoint);
return port;
}
protected CopySoap getCopySoap(String username, String password, String wsdl, String endpoint) throws Exception {
System.out.println("Creating a CopySoap instance...");
Copy service = new Copy(new URL(wsdl), new QName("http://schemas.microsoft.com/sharepoint/soap/", "Copy"));
CopySoap copySoap = service.getCopySoap();
BindingProvider bp = (BindingProvider) copySoap;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
return copySoap;
}
protected QueryServiceSoap getQuerySoap(String username, String password, String wsdl, String endpoint) throws Exception {
System.out.println("Creating a QuerySoap instance...");
QueryService service = new QueryService(new URL(wsdl), new QName("http://microsoft.com/webservices/SharePoint/QueryService", "QueryServiceSoap"));
QueryServiceSoap querySoap = service.getQueryServiceSoap();
BindingProvider bp = (BindingProvider) querySoap;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
return querySoap;
}
答案 0 :(得分:0)
在SharePoint Web Services上进一步教育自己,并查看通过Web提供的示例,我提出了解决方案:
首先检索知道特定文件名的文件,然后使用复制服务。
我不再需要查询SP网站,因为它没有在项目范围内定义。
仍然没有回答如何成功查询SP,但它是我项目的答案。
这是检索文件的代码:
private Document downloadSpFile(CopySoap p, String url) throws IOException {
// Define the variables that will store the output from the web service
// call
System.out.println("Holders...");
Holder<Long> l = new Holder<Long>();
Holder<FieldInformationCollection> myFieldInfoArray = new Holder<FieldInformationCollection>();
Holder<byte[]> myByteArray = new Holder<byte[]>();
System.out.println("Call Web Service...");
// Call the web service
p.getItem(url, l, myFieldInfoArray, myByteArray);
System.out.println("TEST - Write to Disk...");
// Write to file system - TESTING
//Files.write(Paths.get("target-file.pdf"), myByteArray.value);
System.out.println("Convert to Adobe Document");
try {
return new Document(myByteArray.value);
} catch (Exception e) {
System.out.println(e);
return null;
}
}