我是SignalR的新手,他正在开发一个非常小的样本,可能允许签名捕获字段在连接到页面的任何人之间同步。因此,例如,如果两个父母和一个证人都在使用笔记本电脑或手机/平板电脑,并且所有人同时签名,他们就会看到签名发生。此功能将用于会议,每个人都需要签名以验证他们是否出席。
事情是,我看不出有什么不对。打开日志记录后,SignalR不会显示任何明显的错误,并且Developer Tools中的网络面板显示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的Debug窗口中,输出如下
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()<---
有什么想法吗?
我将整个项目投入到一个新的Web项目中,并且100%正常工作,所以我知道我的语法很好。我很困惑。
答案 0 :(得分:0)
从异常消息中,您似乎更新了OWIN或SignalR软件包,并且其中一个方法不再可用。当您转移到新项目时,您通过使用正确的OWIN和SignalR包修复了问题。
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)