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

标签 silverlight ria wcf-ria-services partial-trust

我想使用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.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetForeignKeyMembers()'处理System.TypeAccessException消息=尝试访问安全关键类型System.ComponentModel.DataAnnotations.AssociationAttribute失败。
程序集'System.ComponentModel.DataAnnotations,版本= 4.0.0.0,区域性=中性,PublicKeyToken = 31bf3856ad364e35'是有条件的APTCA程序集,当前应用程序域中未启用该程序集。为了使该组件由部分信任或安全性的透明的代码中使用,请在创建应用程序域时“System.ComponentModel.DataAnnotations,公钥= 0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9”添加集名称所涉及的PartialTrustVisibleAssemblies列表。
源= System.ServiceModel.DomainServices.Server
TypeName =“”
堆栈跟踪:
在System.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetForeignKeyMembers()
在System.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetTypeDescriptor(Type objectType,Object instance)
在System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties()处
在System.ComponentModel.TypeDescriptor.GetProperties(Type componentType)
在System.ServiceModel.DomainServices.Server.DomainServiceDescription.AddEntityType(TypeEntityType)
在System.ServiceModel.DomainServices.Server.DomainServiceDescription.AddQueryMethod(DomainOperationEntry方法)
在System.ServiceModel.DomainServices.Server.DomainServiceDescription.Initialize()
在System.ServiceModel.DomainServices.Server.DomainServiceDescription.CreateDescription(Type domainServiceType)
在System.ServiceModel.DomainServices.Server.DomainServiceDescription。<> c_DisplayClass8.b_7(类型类型)
在System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey key, Func 2 valueFactory)
在System.ServiceModel.DomainServices.Server.DomainServiceDescription.GetDescription(Type domainServiceType)
在System.ServiceModel.DomainServices.Hosting.DomainServiceHost..ctor(类型domainServiceType,Uri [] baseAddresses)
在D:\Users\carlucci\Documents\My Dropbox\My Dropbox\Way2\PartialTrustTest\PartialTrustTest\Program.cs:line 10中的PartialTrustTest.Program.Main(String [] args)
在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String []参数)
在System.AppDomain.nExecuteAssembly(RuntimeAssembly程序集,String []参数)
在System.Runtime.Hosting.ManifestRunner.Run处( bool checkAptModel)
在System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
在System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext,String [] activationCustomData)
在System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
在System.Activator.CreateInstance(ActivationContext activationContext)
在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
在System.Threading.ExecutionContext.Run(ExecutionContext执行上下文,ContextCallback回调,对象状态, bool ignoreSyncCtx)
在System.Threading.ExecutionContext.Run(ExecutionContext执行上下文,ContextCallback回调,对象状态)
在System.Threading.Th

readHelper.ThreadStart()
InnerException:

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

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

任何的想法?

最佳答案

不仅可能,而且这里是完整的代码 list ,为RIA提供了OData,Excel PowerPivot可以使用它。请记住,您必须关闭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();
              }
       }
}

关于silverlight - 是否可以在没有IIS的情况下使用Silverlight RiaServices?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4462550/

相关文章:

c# - RIA 服务/EF。对派生类中 bool 字段的更改不会保存到数据库

wcf-ria-services - RIA服务: Inserting multiple presentation-model objects

c# - 为什么 IEntityCollection 是内部的/如何查找 EntityCollection<T>.Count?

wpf - WPF (Silverlight) 布局 (Render)Transform 对应用性能的影响

c# - 在 Silverlight 应用程序中使用 "dynamic"关键字时出错

silverlight - 从 RIA 服务加载数据时,Silverlight 中的零星 Arg_COMException

JavaFX 自定义组件从自定义组件中的按钮获取操作

c# - 在 QueryBuilder 中使用 or 运算符连接 where 查询

silverlight - 如果支持 VM 的 props 的每个字段都实现 INotifyPropChange,VM 是否需要实现 INotifyPropChagned?

c# - 在 silverlight xaml c# 中只有两个圆角的图像