【问题标题】:Silverlight 4, WCF RIA Services generated incomplete codeSilverlight 4、WCF RIA Services 生成的代码不完整
【发布时间】:2010-07-01 14:30:50
【问题描述】:
  • 我从 Silverlight 业务应用程序模板开始
    • 我将其命名为 MyApp 和 MyApp.Web
  • 我添加了一个新的 SL 应用程序项目。
  • 并添加了指向现有 Web 项目的 ria 链接。
    • 我将调用此加载程序

这个新的 SL 应用程序是我的解决方案的入口点,基本上是从另一个 xap 文件加载主页。检查更新等。

  • 我从 MyApp 中删除了 App.xaml 和 App.xs 文件
  • 因为 Loader 现在是应用程序
    • 我将相关代码从 MyApp - App.cs 复制到 Loader - App.cs
    • 我将相关代码从 MyApp - App.xaml 添加到 Loader - App.xaml
    • 这主要是 WebContext 的东西。

问题在于 Loader 的 RIA 服务生成代码与 MyApp 的代码不同

为 MyApp 生成的代码包含以下命名空间:

  • 我的应用程序
  • MyApp.Web
  • MyApp.Web.Models
  • MyApp.Web.Services

为 Loader 生成的代码包含命名空间:

  • 加载器

Loader 中的以下代码行 - App.cs 抛出 InvalidOperationException

WebContext.Current.Authentication.LoadUser(this.Application_UserLoaded, null);

异常的错误消息是:

DomainContextType 为 null 或无效,并且没有从 AuthenticationBase<T> 生成的上下文

【问题讨论】:

    标签: silverlight wcf-ria-services


    【解决方案1】:

    我今天遇到了同样的问题(使用类似的设置)。看了一圈后,我找到了this post on the silverlight forums,它有答案(在底部寻找解决方案,因为 RIA 服务中有一些 API 更改)。

    长话短说,问题在于您的 WebContext 无法找到在您的情况下处理 LoadUser 的 DomainContext(在本例中为 AuthenticationContext)。要解决此问题,您需要将以下内容添加到您的 App.xaml

    <Application.ApplicationLifetimeObjects>
        <dmnsvc:WebContext>
            <dmnsvc:WebContext.Authentication>
                <appsvc:FormsAuthentication>
                    <appsvc:FormsAuthentication.DomainContext>
                        <!--Your AuthenticationContext here-->
                    </appsvc:FormsAuthentication.DomainContext>
                </appsvc:FormsAuthentication>
            </dmnsvc:WebContext.Authentication>
        </dmnsvc:WebContext>
    </Application.ApplicationLifetimeObjects>
    

    希望这会有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 2011-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多