私は SignalR を初めて使用し、ページに接続しているすべてのユーザー間で署名キャプチャ フィールドを同期できる可能性がある非常に小さなサンプルに取り組んでいます。たとえば、2 人の親と 1 人の証人がすべてラップトップまたは電話/タブレットを使用していて、全員が同時に署名している場合、彼らは署名が行われているのを見ることができます。この機能は、全員が出席を確認するために署名する必要がある会議に再利用されます。
問題は、何が悪いのかわかりません。ログ記録をオンにすると、SignalR は明らかなエラーを表示せず、開発者ツールのネットワーク パネルには POST が表示されますが、何も更新されません。情報がサーバーにスローされ、クライアント間で伝播されることはないようです。
私はこのサンプルを一度に動作させましたが、それを壊すために何をしたかわかりません. ハブを起動するためのコールバックは、jQuery プラグインの「OnDrawEnd」イベントにフックします。また、署名をクリアするためにプラグインが生成する「クリア」ボタンは、「クリアされた」署名を再生成する同じイベントにフックされます。署名して解放した後、POST が発生するとイベントが発生しますが、その後は何も発生しません。
ハブクラスは以下です
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Newtonsoft.Json;
namespace InCare.Modules.SignalRSignature
{
public class SignatureHub : Hub
{
public void UpdateModel(SignModel clientModel)
{
//addMessage is the client-side function that gets called as a callback
Clients.All.updateTheSignature(clientModel);
}
}
public class SignModel
{
[JsonProperty("outputtedSignature")]
string SignatureOutput { get; set; }
}
}
ページ
<!-- References excluded for clarity -->
<script type="text/javascript">
$(function () {
//Set up a connection
var signHub = $.connection.signatureHub;
$.connection.hub.logging = true;
//Default configuration of the SignaturePad plugin
$signPad = $('.sigPad');
$api = $signPad.signaturePad();
//Default signature model
signatureModel = {
outputtedSignature: ""
};
signHub.client.updateTheSignature = function (model) {
//This is never triggered
alert ("This method was hit!!")
signatureModel = model;
$api.regenerate(signatureModel.outputtedSignature);
};
// Start the connection, and when it completes successfully wire up the click handler for the link
$.connection.hub.start().done(function () {
$signPad.signaturePad({
drawOnly : true,
onDrawEnd: function () {
signatureModel.outputtedSignature = $api.getSignatureString();
signHub.server.updateModel(signatureModel);
}
});
$('.clearButton').on("click", function () {
signatureModel.outputtedSignature = $api.clearCanvas();
signHub.server.updateModel(signatureModel);
});
});
});
</script>
<h2>Signature Pad test</h2>
<div class="sigPad">
<label for="name">Print your name</label>
<input type="text" name="name" id="name" class="name">
<p class="typeItDesc">Review your signature</p>
<p class="drawItDesc">Draw your signature</p>
<ul class="sigNav">
<li class="typeIt"><a href="#type-it" class="current">Type It</a></li>
<li class="drawIt"><a href="#draw-it">Draw It</a></li>
<li class="clearButton"><a href="#clear">Clear</a></li>
</ul>
<div class="sig sigWrapper">
<div class="typed"></div>
<canvas class="pad" width="198" height="55"></canvas>
<input type="hidden" name="output" class="output">
</div>
<button id="linkSubmit" type="submit">I accept the terms of this agreement.</button>
</div>
<div id="regeneratedSignature" style="height:400px;width:400px;"></div>
以下のコメントを使用して、スクリーンショットで質問を更新しました。署名を入力し、モデルのoutputtedsignature
プロパティを返された JSON 文字列に設定した後、コンソールからメソッドを呼び出し、次の入力を受け取りました
アップデート
デバッグ モードで実行し、onDrawEnd のコールバックが発生した後、VS2012 のデバッグ ウィンドウで次のように出力されることに気付きました。
w3wp.exe Error: 0 : SignalR exception thrown by Task: System.AggregateException: One or more errors occurred. ---> System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task`1<Microsoft.Owin.IFormCollection> Microsoft.Owin.OwinRequest.ReadFormAsync()'.
at Microsoft.AspNet.SignalR.Owin.ServerRequest.<ReadForm>d__3.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.AspNet.SignalR.Owin.ServerRequest.ReadForm()
at Microsoft.AspNet.SignalR.Transports.ForeverTransport.<ProcessSendRequest>d__10.MoveNext()
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task`1<Microsoft.Owin.IFormCollection> Microsoft.Owin.OwinRequest.ReadFormAsync()'.
at Microsoft.AspNet.SignalR.Owin.ServerRequest.<ReadForm>d__3.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.AspNet.SignalR.Owin.ServerRequest.ReadForm()
at Microsoft.AspNet.SignalR.Transports.ForeverTransport.<ProcessSendRequest>d__10.MoveNext()<---
何か案は?
更新 2
このプロジェクト全体を新しい Web プロジェクトに放り込んだところ、100% 正常に機能したので、構文が適切であることがわかりました。私は困惑している。