【问题标题】:Updating session variable from silverlight through Web Service通过 Web 服务从 silverlight 更新会话变量
【发布时间】:2013-10-11 07:05:51
【问题描述】:

我有一个 aspx 网络表单项目,并且正在使用 Silverlight 组件通过客户端的扫描仪获取图像,一旦扫描完成,我需要将两个字节数组发送到 aspx 会话变量,这样我就可以保存这些字节数组针对一条记录。

我目前只是尝试从 Silverlight 向 aspx 发送一个基本字符串,以尝试更新会话变量(在加强之前尝试让基础工作正常)

当我尝试更新会话变量时,我得到了 NullReferenceException,并从 WebService 得到响应说“NotFound”...

这是我现在拥有的:

网络服务:

namespace XXXX
{
/// <summary>
/// Summary description for EnrollService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class EnrollService : System.Web.Services.WebService
{

    [WebMethod]
    public void SetSessionEmpIDs(string Templates)
    {
        Session.Add("EmployeeIDs", Templates);
    }
}
}

银光面:

EnrollServiceReference.EnrollServiceSoapClient client = new EnrollServiceReference.EnrollServiceSoapClient();
client.SetSessionEmpIDs("IDsDONE");

【问题讨论】:

标签: c# web-services silverlight nullreferenceexception


【解决方案1】:

尝试发送文件的 byte[] 数组块(~ 1024 字节或更多,您需要找出适合您的配置/客户端环境的最佳大小)并将它们组装到服务器上 - 这是更可行和灵活的方法('向量数组的块文件表示更自然+服务绑定/通道有发送/接收数据大小限制)。

而且我完全不建议使用对象和接口 WCF 方法参数/返回类型,因为这会导致与某些客户端不兼容(根据 WS 标准/规范)

【讨论】:

  • 嗨@SalientBrain,谢谢你的评论,但是自从这篇文章遇到了其他问题,只是让Web服务的基础工作正常,也许你可以帮忙?
  • 嗨 SalientBrain 和@John Saunders,我找到了一个解决方法,除了现在使用会话变量(尽管我面临另一个问题 - 新帖子),因为我花了很多时间关于这个任务......我将来可能会重新审视这个,但感谢你们两位的 cmets。作为记录,我看不到如何通过服务更新会话变量,因为服务没有引用要访问的用户会话变量(我相信这就是为什么 NullReference)但是我将来可能会被证明是错误的.
猜你喜欢
  • 1970-01-01
  • 2016-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多