簡體   English   中英

無法使用.NET Tin Can Library連接到LRS

[英]Unable to connect to the LRS using the .NET Tin Can Library

我正在嘗試使用.NET TinCan庫在我自己的學習管理系統中使用。 我在我的應用程序中包含了TinCan 0.0.2 Nuget包,並上傳了GolfExample_TCAPI測試課程。 在本地測試時,GolfExample課程將加載以下URL:

https://127.0.0.1/TINCAN/MYCOMPANY/GolfExample_TCAPI%20(1)/index.html?

在查看我可以找到的啟動文檔時,似乎至少需要傳入端點,auth和actor,因此我嘗試在我的viewmodel中使用dll進行如下操作。

var lrs = new RemoteLRS("https://cloud.scorm.com/tc/public/", "<username>", "<password>");

var actor = new TinCan.Agent();
actor.name = "John Paul Mc Feely";
actor.mbox = "jpmcfeely@hsl-data.com";

TINCANStartPage = HttpContext.Current.Request.Url.Scheme + "://" + @HttpContext.Current.Request.Url.Host + ":" +
                @HttpContext.Current.Request.Url.Port + HttpContext.Current.Request.ApplicationPath + this.Course.BlobURL + "/index.html" + "?endpoint=" + lrs.endpoint + "&auth=" + lrs.auth + "&actor=" + actor.ToJSON();  

調試時我可以看到這創建了啟動窗口的URL,如下所示:

"https://127.0.0.1/TINCAN/MYCOMPANY/GolfExample_TCAPI (1)/index.html?endpoint=https://cloud.scorm.com/tc/public/&auth=Basic anBtY2ZlZWx5QGhzbC1kYXRhLmNvbTpwbGFzbWExMQ==&actor={\"objectType\":\"Agent\",\"name\":\"John Paul Mc Feely\",\"mbox\":\"jpmcfeely@hsl-data.com\"}"

根據我可以看到的文檔,這看起來像正確的格式但是當我繼續使用URL啟動窗口時:

https://127.0.0.1/TINCAN/MYCOMPANY/GolfExample_TCAPI%20(1)/index.html?endpoint=https://cloud.scorm.com/tc/public/&amp;auth=Basic%20anBtY2ZlZWx5QGhzbC1kYXRhLmNvbTpwbGFzbWExMQ==&amp;actor={&quot;objectType&quot;:&quot;Agent&quot;,&quot;name&quot;:&quot;John%20Paul%20Mc%20Feely&quot;,&quot;mbox&quot;:&quot;jpmcfeely@hsl-data.com&quot;}

然后我收到如下警告信息:

[警告]與學習記錄存儲器通信時出現問題。 (400 |陳述3bd49829-dc0b-4daa-a689-71a84c44e6ad沒有分配演員。)

如果有人能夠看到我在這里做錯了什么,我將不勝感激。

最小的查詢字符串參數需要URLEncoded。 您需要在actor.ToJSON()中包裝lrs.endpointlrs.authHttpUtility.UrlEncode()

using System.Web;

TINCANStartPage = HttpContext.Current.Request.Url.Scheme + 
    "://" + 
    @HttpContext.Current.Request.Url.Host +
    ":" +
    @HttpContext.Current.Request.Url.Port + 
    HttpContext.Current.Request.ApplicationPath + 
    this.Course.BlobURL + 
    "/index.html" + 
    "?endpoint=" + 
    HttpUtility.UrlEncode(lrs.endpoint) + 
    "&auth=" + 
    HttpUtility.UrlEncode(lrs.auth) + 
    "&actor=" + 
    HttpUtility.UrlEncode(actor.ToJSON());

基於警告消息,聽起來你正在將它傳遞給TinCanJS。 我們需要查看該代碼以進一步排除故障。 實例化TinCan對象的代碼需要將url傳遞給解析,這似乎有效,但是由於URL編碼不正確而找不到actor。

請注意,您使用該響應獲得400狀態意味着它已成功連接到LRS,因此請求中發送的內容無效。

我通過在ViewModel上執行以下操作來實現此目的:

//Initialize the LRS
var lrs = new RemoteLRS("https://cloud.scorm.com/tc/public/", "<username>", "<password>");  

//Initialize the TinCan Actor for Launch String
this.Actor = new TinCan.Agent();
this.Actor.name = this.User.Forename + " " + this.User.Surname;
this.Actor.mbox = this.User.Email;

//Construct the TinCanStartPage
TINCANStartPage = HttpContext.Current.Request.Url.Scheme + "://" + @HttpContext.Current.Request.Url.Host + ":" +
                @HttpContext.Current.Request.Url.Port + HttpContext.Current.Request.ApplicationPath + this.Course.BlobURL + this.LaunchPage;

然后在從我啟動TinCan窗口的視圖中,我有以下內容:

$(document).ready(function () {

    var myActor = '@Html.Raw(Model.Actor.ToJSON())';        
    var launchLink = '@Model.TINCANStartPage' + '?endpoint=' + '@Model.LRS.endpoint' + '&auth=' + '@Model.LRS.auth' + '&actor=' + myActor;
    window.open(launchLink, "SCORM", "width=1140,height=760,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0");

});

function relaunch() {        
    var relaunchLink = '@Model.TINCANStartPage' + '?endpoint=' + '@Model.LRS.endpoint' + '&auth=' + '@Model.LRS.auth' + '&actor=' + myActor;
    window.open(relaunchLink, 'SCORM', 'width=1140,height=760,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM