Silverlight 4,WCF RIA Services生成的代码不完整(Silverlight 4, WCF RIA Services generated incomplete code)

编程入门 行业动态 更新时间:2024-10-28 00:27:00
Silverlight 4,WCF RIA Services生成的代码不完整(Silverlight 4, WCF RIA Services generated incomplete code) 我从Silverlight业务应用程序模板开始 我将这个称为MyApp和MyApp.Web 我添加了一个新的SL应用程序项目。 并添加了一个ria链接到现有的Web项目。 我会称这个装载机

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

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

问题是RIA Services为Loader 生成的代码与MyApp代码的代码不同

生成的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>生成的上下文

I started with the Silverlight Business Application Template I will call this MyApp and MyApp.Web I added a new SL application project. and added a ria link to the existing web project. I will call this Loader

This new SL app is the entry point of my solution, and basically loads the mainpage from the other xap file. Checks for updates, etc.

I removed the App.xaml and App.xs files from MyApp Because Loader is now the Application I copied the relevant code from MyApp - App.cs to Loader - App.cs I added the relevant code from MyApp - App.xaml to Loader - App.xaml Mostly this is the WebContext stuff.

The problem is that the RIA Services generated code for Loader is not the same code as the code for MyApp

The generated code for MyApp contains the following namespaces:

MyApp MyApp.Web MyApp.Web.Models MyApp.Web.Services

The generated code for Loader contains the namespace:

Loader

The following line of code in Loader - App.cs throws InvalidOperationException.

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

The error msg for the exception is:

The DomainContextType is null or invalid and there are no contexts generated from AuthenticationBase<T>

最满意答案

我今天遇到了同样的问题(有类似的设置)。 看了一下之后,我在silverlight论坛上找到了这个帖子,它有答案(在底部查找解决方案,因为RIA Services中有一些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>

希望这可以帮助 :)

I've had this same problem (with a similar setup) today. After looking around a little bit, I found this post on the silverlight forums which has the answer (look in the bottom for the solution, since there were some API changes in RIA Services).

Long story short, the issue is that your WebContext can't find the DomainContext (in this case an AuthenticationContext) that handles LoadUser in your case. to solve this problem you'll need to add the following to your 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>

Hope this helps :)

更多推荐

本文发布于:2023-08-07 15:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464784.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不完整   代码   RIA   Silverlight   WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!