【问题标题】:RIA Service Error in a Silverlight ApplicationSilverlight 应用程序中的 RIA 服务错误
【发布时间】:2018-02-18 17:39:51
【问题描述】:

在一个非常简单的 Silverlight 应用程序中,我有一个 DomainService 类,它有一个返回字母对象列表的方法。

当我在 VisualStudio 中运行该应用程序时,它运行良好。但是,当我将它发布到我的 Windows 10 本地计算机上的文件夹并使用 IIS(版本 10.0.166299.5)运行它时,我收到以下错误:

远程服务器返回错误:NotFound。 在 System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error) 在 System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error) 在 System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult) 在 System .ServiceModel.DomainServices.Client.DomainContext.c__DisplayClass1b.b__17(Object )

我怀疑这是因为我的 WebConfig 文件中缺少某些错误。 我的 WebConfig 目前如下所示:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>

    <system.web>
      <compilation debug="true" targetFramework="4.6" />
      <httpRuntime targetFramework="4.6" />
    </system.web>




  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </modules>
  </system.webServer>


  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>


</configuration>

我的域服务类的代码是这样的:

using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using SilverData.Web.Models;

namespace SilverData.Web.Services
{
    [EnableClientAccess]
    public class DrugsRiaService : DomainService
    {


        public IQueryable<Letter> GetAllLetters()
        {
            List<Letter> letters = new List<Letter>();

            Letter letterA = new Letter { ID = 1, Statement = "Mike" };
            Letter LetterB = new Letter { ID = 2, Statement = "Emma" };
            Letter LetterC = new Letter { ID = 3, Statement = "Peter" };

            letters.Add(letterA);
            letters.Add(LetterB);
            letters.Add(LetterC);



            return letters.AsQueryable();
        }


    }
}

【问题讨论】:

    标签: silverlight web-config wcf-ria-services


    【解决方案1】:

    错误是由于 .svc 文件没有被提供的问题。在 Kyle Abraham on Experts Exchange 的帮助下,问题得到了解决。

    https://www.experts-exchange.com/questions/29084691/RIA-Service-Error-in-a-Silverlight-Application.html

    解决方案是将以下行添加到 Webconfig 的 webserver 部分

    <handlers>
      <add name=".svc" verb="*" path="*.svc" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </handlers>
    

    【讨论】:

      【解决方案2】:

      我不确定,这是一个猜测,因为我有一段时间没有使用 RIA,但我认为字母需要作为可查询以外的东西返回...尝试 ToList() 导致查询执行,以及有效负载从数据库中检索到的完整枚举是完整的。请记住,这是来自客户端的远程调用,而不是可以扩展可查询对象的本地调用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-05
        • 1970-01-01
        相关资源
        最近更新 更多