2014-02-10 116 views
5

我想在工作中爲我的SharePoint服務器創建一個簡單的CRUD跨平臺移動應用程序。我使用PhoneGap來處理跨平臺編碼 - 因此我的代碼將使用HTML,CSS和JavaScript。爲SharePoint 2013創建跨平臺移動應用程序

我所擁有的主要障礙是使用我的SharePoint服務器進行身份驗證。很多人在網上已經成功地使用AJAX調用,但是我收到以下錯誤:

XMLHttpRequest cannot load http://<DOMAIN>/_vti_bin/authentication.asmx. The request was redirected to 'http://<DOMAIN>/_layouts/15/error.aspx?ErrorText=Request%20format%20is%20unrecognized%2E', which is disallowed for cross-origin requests that require preflight. 

以下是我的JavaScript代碼:

function Authenticate() { 
    $.support.cors = true; 
    $.mobile.allowCrossDomainPages = true; 

    $("#topnavcontent").append("Creating SOAP envelope...</br>"); 

    var soapEnv = "<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>" + 
    "<Login xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">" + 
    "<username>USERNAME</username>" + 
    "<password>PASSWORD</password>" + 
    "</Login>" + 
    "</soap:Body>" + 
    "</soap:Envelope>"; 

    $("#topnavcontent").append("Calling authenticate.asmx...</br>"); 

    $.ajax({ 
     url: "http://<DOMAIN>/_vti_bin/authentication.asmx", 
     type: "POST", 
     data: soapEnv, 
     complete: authenticationResultSuccess, 
     contentType: "text/xml; charset=\"utf-8\"", 
     error: authenticationResultError 
    }); 
} 

我瞭解瀏覽器發送飛行前OPTIONS調用。默認情況下,SharePoint網站不支持OPTIONS調用。是否有任何解決方法,例如禁用此OPTIONS調用或SharePoint網站上的webconfig中的設置,以允許通過預先調用。先謝謝您的幫助。

+0

你有沒有設置'<訪問起源= 「*」/>'在你的config.xml爲的PhoneGap項目使用此API目前原生的Android樣? –

+0

愚蠢的問題,但您的Sharepoint服務器是否接受跨域請求? – AymKdn

+0

@AymKdn SharePoint站點將「Access-Control-Allow-Origin」設置爲「*」。 – DrEvans

回答

1

Office 365 API旨在用於移動應用程序和獨立Web應用程序。更多詳細信息,請訪問:http://msdn.microsoft.com/en-us/library/office/dn605892(v=office.15).aspx

使用新的Office 365 API對Azure AD進行身份驗證後,實際上可以將SharePoint CSOM和REST API與auth承載一起使用。

您是否檢出了Visual Studio 2013中的Cordova(PhoneGap)項目類型?當您在解決方案資源管理器中的項目節點上添加連接以連接到Office 365 API時,會生成js文件。

很快,我們將在MS TechEd NA Keynote上演示的WoodGrove應用程序的代碼示例在http://www.github.com/OfficeDev

有通過Android SDK這裏https://github.com/OfficeDev/Office-365-SDK-for-Android