使用Copy.CopyIntoItems Web服务将文件上载到SharePoint 2010时获取400错误请求 [英] Gettting 400 Bad Request while uploading file to SharePoint 2010 using Copy.CopyIntoItems web service

查看:120
本文介绍了使用Copy.CopyIntoItems Web服务将文件上载到SharePoint 2010时获取400错误请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SharePoint的新功能。

New to SharePoint.

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

I'm trying to upload a document to SharePoint using it's CopyIntoItems web service method with Java but keep on getting 400 Bad Request. I've use the Java's wsimport to generate the class files from the .wsdl file. Here is my Java code with the generated classes.

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<CopyResultCollection> resultHolder = new Holder<CopyResultCollection>(results);

    Holder<Long> longHolder = new Holder<Long>(new Long(-1));

    port.copyIntoItems(sourceUrl, urls, infos, content, longHolder, resultHolder);

}

我的SOAP请求看起来像

My SOAP Request looks like

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <CopyIntoItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">    
         <SourceUrl>http://null</SourceUrl>
         <DestinationUrls>
            <string>https://www.mysite.com/sites/TestSite/Shared Documents/Temp Folder/test.txt</string>
         </DestinationUrls>
         <Fields>
            <FieldInformation Value="Test uploaded file" DisplayName="Test Doc" Type="Text"/>
         </Fields>
         <Stream>KioqTWFrZSBzdXJlIHRoZSBjb250ZW50IGlzIHVuZGVyIEM6L0NvcHlGaWxlLy4gICoqKg0KDQpUbyBydW46DQoNCjEuICBFZGl0IHRoZSBkZXBsb3kucHJvcHMgZmlsZS4gIFNwZWNpZnkgdGhlIHNvdXJjZSAoZm9sZGVyIHRoYXQgY29udGFpbiBpdGVtcyB0byBkZXBsb3kpLCBkZXN0aW5hdGlvbiAoZm9sZGVyIHRvIGRlcGxveSB0byksIGFuZCBmaWxlcyAodGhlIGl0ZW1zIHRvIGRlcGxveSkuDQoyLiAgRG91YmxlIGNsaWNrIG9uIGRlcGxveUN1c3RvbWl6YXRpb24uYmF0DQoNCk5vdGUgdGhhdCBhIGxvZyBvZiB0aGUgcHJvZ3Jlc3Mgd2lsbCBiZSBjcmVhdGVkIGluIEM6L0NvcHlGaWxlL2NvcHlGaWxlLmxvZyANCg0KTm90ZSB0aGF0LCBmb3IgcHJlY2F1dGlvbiwgZXhpc3RpbmcgZmlsZSB3aWxsIG5vdCBiZSBvdmVyd3JpdHRlbiwgaW5zdGVhZCB3aWxsIGJlIHNhdmVkIGFzIHlvdXJfY29kZV9maWxlLm9sZA==</Stream>
      </CopyIntoItems>
    </S:Body>
</S:Envelope>

我得到的回复是

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

这对我来说并不多。可能缺少什么?

which doesn't tell me much. What could be missing?

推荐答案

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

Got it! There is just a bug in my code in initialization. Here is the working code to anyone out there looking to work with SharePoint and Java. I've use JAX-WS wsimport tool to generate the class file from the .wsdl file. You can point the tool straight to the url of the WSDL, for example, 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<CopyResultCollection> resultHolder = new Holder<CopyResultCollection>(results);      

    Holder<Long> longHolder = new Holder<Long>(new Long(-1));       

    port.copyIntoItems(sourceUrl, urls, infos, content, longHolder, resultHolder);

}

这篇关于使用Copy.CopyIntoItems Web服务将文件上载到SharePoint 2010时获取400错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆