是否可以在没有 IIS 的情况下使用 Silverlight RiaServices?

发布于 2024-10-07 14:53:39 字数 4332 浏览 1 评论 0原文

我想使用 silverlight 作为我的 Windows 服务接口。为此,我使用自定义 Web 服务器来提供 xap 文件,并且运行良好。

现在我想使用RiaServices,但是当然我没有涉及IIS。

这是我的代码:

[EnableClientAccess]
public class TestDomainService : DomainService {

    public IQueryable<Foo> GetPontos() {
        List<Foo> list = new List<Foo>();
        list.Add(new Foo {Id = 1});
        return list.AsQueryable();
    }
}

public class Foo {
    [Key]
    public int Id { get; set; }
    public string Name { get; set; }
}

和程序:

static void Main(string[] args) {      
      DomainServiceHost host = new DomainServiceHost(typeof(TestDomainService), new Uri("http://0.0.0.0:8099/TestDomainService"));
      host.Open();
}

您可以在空的cmd应用程序中使用此代码,一旦您点击播放,就会引发运行时异常:

System.TypeAccessException未处理消息=安全透明方法'System.ServiceModel.DomainServices.Server的尝试.DomainTypeDescriptionProvider.GetForeignKeyMembers()'访问安全关键类型System.ComponentModel.DataAnnotations.AssociationAttribute'失败。 程序集“System.ComponentModel.DataAnnotations,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”是一个有条件的 APTCA 程序集,在当前 AppDomain 中未启用。要使该程序集能够被部分信任或安全透明代码使用,请添加程序集名称 'System.ComponentModel.DataAnnotations, PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8F DE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C4创建 AppDomain 时,将 54307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9' 添加到 PartialTrustVisibleAssemblies 列表中。 源=System.ServiceModel.DomainServices.Server 类型名称=“” 堆栈跟踪: 在 System.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetForeignKeyMembers() 在 System.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetTypeDescriptor(类型 objectType,对象实例) 在 System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties() 在 System.ComponentModel.TypeDescriptor.GetProperties(类型组件类型) 在 System.ServiceModel.DomainServices.Server.DomainServiceDescription.AddEntityType(类型实体类型) 在 System.ServiceModel.DomainServices.Server.DomainServiceDescription.AddQueryMethod(DomainOperationEntry 方法) 在 System.ServiceModel.DomainServices.Server.DomainServiceDescription.Initialize() 在System.ServiceModel.DomainServices.Server.DomainServiceDescription.CreateDescription(类型domainServiceType) 在 System.ServiceModel.DomainServices.Server.DomainServiceDescription.<>c_DisplayClass8.b_7(类型类型) 在 System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) 在System.ServiceModel.DomainServices.Server.DomainServiceDescription.GetDescription(类型domainServiceType) 在 System.ServiceModel.DomainServices.Hosting.DomainServiceHost..ctor(类型domainServiceType,Uri [] baseAddresses) 在 D:\Users\carlucci\Documents\My Dropbox\My Dropbox\Way2\PartialTrustTest\PartialTrustTest\Program.cs 中的 PartialTrustTest.Program.Main(String[] args):第 10 行 在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,String[] args) 在 System.AppDomain.nExecuteAssembly(RuntimeAssembly 程序集,String[] args) 在 System.Runtime.Hosting.ManifestRunner.Run(布尔 checkAptModel) 在 System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() 在 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContextactivationContext,String[]activationCustomData) 在System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContextactivationContext) 在 System.Activator.CreateInstance(ActivationContext 激活上下文) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallback回调,对象状态,布尔ignoreSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallback 回调,对象状态) 在 System.Threading.Th

readHelper.ThreadStart() InnerException:


我尝试将 System.ComponentModel.DataAnnotations 添加到 APTCA,但没有成功 :(

我将应用程序更改为完全信任地运行,但没有成功 :(

有什么想法吗?

I want to use silverlight as my windows service interface. For that, I'm using a custom web server to provide the xap file and it works fine.

Now I want to use RiaServices, but of course I there is no IIS involved.

Here is my code:

[EnableClientAccess]
public class TestDomainService : DomainService {

    public IQueryable<Foo> GetPontos() {
        List<Foo> list = new List<Foo>();
        list.Add(new Foo {Id = 1});
        return list.AsQueryable();
    }
}

public class Foo {
    [Key]
    public int Id { get; set; }
    public string Name { get; set; }
}

And Program:

static void Main(string[] args) {      
      DomainServiceHost host = new DomainServiceHost(typeof(TestDomainService), new Uri("http://0.0.0.0:8099/TestDomainService"));
      host.Open();
}

You can use this code in an empty cmd application and once you hit play, a runtime exception is thrown:

System.TypeAccessException was unhandled Message=Attempt by security transparent method 'System.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetForeignKeyMembers()' to access security critical type System.ComponentModel.DataAnnotations.AssociationAttribute' failed.
Assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is a conditionally APTCA assembly which is not enabled in the current AppDomain. To enable this assembly to be used by partial trust or security transparent code, please add assembly name 'System.ComponentModel.DataAnnotations, PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9' to the the PartialTrustVisibleAssemblies list when creating the AppDomain.
Source=System.ServiceModel.DomainServices.Server
TypeName=""
StackTrace:
at System.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetForeignKeyMembers()
at System.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetTypeDescriptor(Type objectType, Object instance)
at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties()
at System.ComponentModel.TypeDescriptor.GetProperties(Type componentType)
at System.ServiceModel.DomainServices.Server.DomainServiceDescription.AddEntityType(Type entityType)
at System.ServiceModel.DomainServices.Server.DomainServiceDescription.AddQueryMethod(DomainOperationEntry method)
at System.ServiceModel.DomainServices.Server.DomainServiceDescription.Initialize()
at System.ServiceModel.DomainServices.Server.DomainServiceDescription.CreateDescription(Type domainServiceType)
at System.ServiceModel.DomainServices.Server.DomainServiceDescription.<>c_DisplayClass8.b_7(Type type)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
at System.ServiceModel.DomainServices.Server.DomainServiceDescription.GetDescription(Type domainServiceType)
at System.ServiceModel.DomainServices.Hosting.DomainServiceHost..ctor(Type domainServiceType, Uri[] baseAddresses)
at PartialTrustTest.Program.Main(String[] args) in D:\Users\carlucci\Documents\My Dropbox\My Dropbox\Way2\PartialTrustTest\PartialTrustTest\Program.cs:line 10
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Th

readHelper.ThreadStart()
InnerException:


I tried to add System.ComponentModel.DataAnnotations to the APTCA, but no success :(

I changed my application to run in full trust, but no success :(

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

混吃等死 2024-10-14 14:53:39

这不仅是可能的,而且这里有一个完整的代码清单,它为 RIA 提供了可由 Excel PowerPivot 使用的 OData。请记住,您必须关闭 Visual Studio 托管进程,或者直接运行而不进行调试。使用 PowerPivot 时,请记住包含尾部斜杠,以便您的 URL 为: http://localhost:999/TestDomainService/

using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.ServiceModel.Activation;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;

namespace ConsoleApplication1
{
       public partial class Program
       {
              [EnableClientAccess]
              public class TestDomainService : DomainService
              {
                     [Query(IsDefault=true)]
                     public IQueryable<Foo> GetAllFoos()
                     {
                           return new Foo[] { new Foo { Id = 1, Name = "Jonathan" } }.AsQueryable();
                     }
              }

              public class Foo
              {
                     [Key]
                     public int Id { get; set; }
                     public string Name { get; set; }
              }

              static void Main(string[] args)
              {
                     var svc = new DomainServiceHost(typeof(TestDomainService), new Uri[] { new Uri("http://localhost:999/TestDomainService") });
                     svc.Description.Behaviors.RemoveAll<AspNetCompatibilityRequirementsAttribute>();

                     var svcDescription = DomainServiceDescription.GetDescription(typeof(TestDomainService));
                     var endpoints = new ODataEndpointFactory().CreateEndpoints(svcDescription, svc);

                     svc.Description.Endpoints.Clear();

                     foreach (var endpoint in endpoints)
                     {
                           svc.Description.Endpoints.Add(endpoint);
                     }

                     svc.Open();

                     Console.WriteLine("Domain service started, press any key to exit.");
                     Console.ReadKey();
              }
       }
}

Not only is it possible, but here's a full code listing that provides RIA with OData which is consumable by Excel PowerPivot. Remember that you must turn off the visual studio hosting process, or just run without debugging. When using PowerPivot remember to include the trailing slash so your URL will be: http://localhost:999/TestDomainService/

using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.ServiceModel.Activation;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;

namespace ConsoleApplication1
{
       public partial class Program
       {
              [EnableClientAccess]
              public class TestDomainService : DomainService
              {
                     [Query(IsDefault=true)]
                     public IQueryable<Foo> GetAllFoos()
                     {
                           return new Foo[] { new Foo { Id = 1, Name = "Jonathan" } }.AsQueryable();
                     }
              }

              public class Foo
              {
                     [Key]
                     public int Id { get; set; }
                     public string Name { get; set; }
              }

              static void Main(string[] args)
              {
                     var svc = new DomainServiceHost(typeof(TestDomainService), new Uri[] { new Uri("http://localhost:999/TestDomainService") });
                     svc.Description.Behaviors.RemoveAll<AspNetCompatibilityRequirementsAttribute>();

                     var svcDescription = DomainServiceDescription.GetDescription(typeof(TestDomainService));
                     var endpoints = new ODataEndpointFactory().CreateEndpoints(svcDescription, svc);

                     svc.Description.Endpoints.Clear();

                     foreach (var endpoint in endpoints)
                     {
                           svc.Description.Endpoints.Add(endpoint);
                     }

                     svc.Open();

                     Console.WriteLine("Domain service started, press any key to exit.");
                     Console.ReadKey();
              }
       }
}
两相知 2024-10-14 14:53:39

您可以在没有 IIS 的情况下使用 RIA 服务。打开之前配置域服务:

DomainServiceHost host = new DomainServiceHost(typeof(DomainService1), uri);
host.Description.Behaviors.Remove<AspNetCompatibilityRequirementsAttribute>();

还要检查 exe 文件的 *.config,因为我记得有一些与 IIS 相关的设置,您必须删除这些设置。

并且在 VS 的项目属性中,打开“调试”选项卡并取消选中“启用 Visual Studio 托管进程”。

You can use RIA Services without IIS. Configure the domain service before opening:

DomainServiceHost host = new DomainServiceHost(typeof(DomainService1), uri);
host.Description.Behaviors.Remove<AspNetCompatibilityRequirementsAttribute>();

Also check the *.config of your exe-file, as I remember there was some settings related to IIS which you have to remove.

And also in the project properties in VS, open "Debug" tab and uncheck "Enable the Visual Studio hosting process".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文