从Adobe Acrobat X Javascript调用Web服务

时间:2011-10-24 13:37:10

标签: javascript web-services soap sharepoint-2007 acrobat

我正在尝试从Acrobat JavaScript调用SharePoint Web服务,我遇到了一个我似乎无法解决的错误。希望能帮助我调用sharepoint做错的事情。我已经看到了两种对Web服务进行SOAP调用的方法:

方式1:

var strURL = "http://www.webservicex.net/globalweather.asmx?wsdl";
      var service = SOAP.connect(strURL);
      var sCountryName = "United States";
      var sCityName = "New York";
      var result = {
                  soapType: "xsd:string",
                 CountryName: sCountryName,
                   CityName: sCityName
                   //soapValue:
                  };
      var results = service.GetWeather(result);

当我直接复制代码时,这是有效的,但是当我尝试用我的代码替换它时,我得到“service is undefined”错误消息:

var strURL = "http://dev-dc:40570/branches/GHIS/XXXXXXX/_vti_bin/lists.asmx?wsdl";
      var service = SOAP.connect(strURL);

      var sPageURL = "http://devdc:40570/branches/GHIS/XXXXXXX/Other%20Client%20Documents/XXXXXXX.pdf";
      var sCheckoutToLocal = "false";
      var sLastModified = "";
      var result = {
                    soapType: "xsd:string",
                    pageURL: sPageURL,
                    checkoutToLocal: sCheckoutToLocal,
                    LastModified: sLastModified
                  };
      var results = service.CheckOutFile(result);

由于这不起作用,我尝试了方法2来调用webservice:

var oAuthenticator ={ UsePlatformAuth: "true"};
var cURL = "http://www.webservicex.net/globalweather.asmx";
var oRequest = {"http://www.webserviceX.NET:GetWeather":{CityName:"New York",CountryName:"United States"}};
var cAction = "http://www.webserviceX.NET/GetWeather";
var ver = SOAPVersion.version_1_2;
SOAP.wireDump = "true";
var response = Net.SOAP.request({cURL:cURL,oRequest:oRequest,cAction:cAction,oAuthenticate:oAuthenticator,bEncoded:false,cVersion:ver});

虽然说没有提供CountryName,但我遇到了这种风格的错误。使用我的代码,我得到一个类似的错误,说pageUrl丢失或无效:

var oAuthenticator ={ UsePlatformAuth: "true"};
    var cURL = "http://dev-dc:40570/branches/GHIS/XXXXXXX/_vti_bin/lists.asmx?wsdl";
    var oRequest = {
        "http://schemas.microsoft.com/sharepoint/soap:CheckOutFile":{
            pageUrl:"http://dev-dc:40570/branches/GHIS/XXXXXXX/Other%20Client%20Documents/XXXXXXX.pdf",
            checkoutToLocal:"false",
            lastmodified:""
            }};
    var cAction = "http://schemas.microsoft.com/sharepoint/soap/CheckOutFile";
    var ver = SOAPVersion.version_1_1;
    SOAP.wireDump = "true";
    var response = SOAP.request({
        cURL:cURL,
        oRequest:oRequest,
        cAction:cAction,
        oAuthenticate:oAuthenticator,
        bEncoded:false,
        cVersion:ver
        });

有人可以帮我弄清楚为什么我似乎无法调用此SharePoint Web服务?我不关心我使用哪种方法,只要我可以从Acrobat的javascript中与web服务交谈。此外,如果它有帮助,这是在浏览器中手动导航到Web服务时的推荐调用:

POST /_vti_bin/lists.asmx HTTP/1.1
Host: dev-dc
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <CheckOutFile xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <pageUrl>string</pageUrl>
      <checkoutToLocal>string</checkoutToLocal>
      <lastmodified>string</lastmodified>
    </CheckOutFile>
  </soap12:Body>
</soap12:Envelope>

1 个答案:

答案 0 :(得分:1)

在做了一些实验之后,我了解到,不是使用acrobat来构建代码的请求部分,而是可以传递原始XML,它将完全按照键入的方式传递它。因此,我确定sharepoint必须寻找XML结构的特定方式。通过更改代码来传递XML Sharepoint和Acrobat能够成功通信。修订后的(工作)代码如下所示:

/**WebService Call to the Sharepoint Lists service for Checking Out the current document**/
function CheckOutFile(myFileVal){
    var oAuthenticator ={ UsePlatformAuth: "true"};
    var cURL = GetDocLibraryWS(myFileVal.path); 
    var oRequest = {
        soapValue: "<CheckOutFile xmlns='http://schemas.microsoft.com/sharepoint/soap/'>"+
                        "<pageUrl>"+myFileVal.path+"</pageUrl>"+
                        "<checkoutToLocal>false</checkoutToLocal>"+
                        "<lastmodified/>"+
                    "</CheckOutFile>"};
    var cAction = "http://schemas.microsoft.com/sharepoint/soap/CheckOutFile";
    var ver = SOAPVersion.version_1_2;
    var response = SOAP.request({
        cURL:cURL,
        oRequest:oRequest,
        cAction:cAction,
        oAuthenticate:oAuthenticator,
        bEncoded:false,
        cVersion:ver
        });}
/**derives the document library web service path from the file URL**/
function GetDocLibraryWS(myFile){
    var myString = myFile.substring(0,myFile.lastIndexOf("/"));
    myString = myString + "/_vti_bin/Lists.asmx";
    return myString;}