0

我是 SignalR 的新手,正在研究一个非常小的样本,该样本可能允许签名捕获字段在连接到页面的任何人之间同步。因此,例如,如果两个父母和一名证人都使用笔记本电脑或手机/平板电脑,并且都同时签名,他们可以看到签名正在发生。此功能将重新用于需要每个人签名以验证他们是否出席的会议。

问题是,我看不出有什么问题。启用日志记录后,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 字符串后,从控制台调用该方法并收到以下输入

SignalR 签名 Firebug 提示

更新

在调试模式下运行,触发 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()<---

有任何想法吗?

更新 2

我把整个项目扔进了一个新的网络项目,它工作得 100% 好,所以我知道我的语法很好。我很混乱。

4

1 回答 1

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)

于 2013-11-04T18:06:13.770 回答