2010-12-16 108 views
4

我想使用silverlight作为我的windows服务接口。为此,我使用自定义Web服务器来提供xap文件,并且它工作正常。是否可以在没有IIS的情况下使用Silverlight RiaServices?

现在我想使用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未处理Message =尝试通过安全透明方法'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,公钥= 0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9”到的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 (Type entityType) at System.ServiceModel.DomainServices.Server.DomainServiceDescription.AddQueryMethod(Domain OperationEntry方法) 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(类型类型) 在System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey key, Func 2 valueFactory) 在System.ServiceModel.DomainServices.Server.DomainServiceDescription.GetDescription(类型domainServiceType) 在System.ServiceModel.DomainServices .Hosting.DomainServiceHost..ctor(类型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,字符串[] activationCustomData) 在System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) 在System.Activator.CreateInstance(ActivationContext activationContext) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() 在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,System.Threading.ExecutionContext.Run)上执行System.Threading.ThreadHelper.ThreadStart_Context(Object state) (ExecutionContext executionContext,ContextCallback callback,Object state,Boolean ignoreSyncCtx) 对象状态) at System.Threading.Th

readHelper.ThreadStart() 的InnerException:


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

我改变了我的应用程序在完全信任运行,但没有成功:(

任何想法?

+0

如果你在调试模式下运行时,一定要到项目属性 - >调试 - >取消选中“启用在Visual Studio托管过程“,你会停止得到这个错误。 – 2012-01-19 19:03:11

回答

0

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

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

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

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

1

这不仅是可能的,但是这里有一个完整的代码列表,它提供了可以通过Excel PowerPivot使用的OData的RIA。请记住,您必须关闭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(); 
       } 
     } 
} 
相关问题