Can I use Silverlight RiaServices without IIS?

I want to use silverlight as my windows service interface. For this, I use a custom web server to provide the xap file, and it works great.

Now I want to use RiaServices, but, of course, I do not participate in IIS.

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 the 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 after you click the game, an exception is thrown for execution:

System.TypeAccessException was unhandled. Message = Attempted by a transparent security method. System.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetForeignKeyMembers () 'to access the critical security type. System.ComponentModel.DataAnnotations.AssociationAttribute 'failed. Assembly 'System.ComponentModel.DataAnnotations, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35' is an APTCA conditional assembly that is not included in the current AppDomain. To enable the assembly that will be used by partially transparent or trust the security code, please add the name of the assembly "System.ComponentModel.DataAnnotations, PublicKey = 0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9" in the list on PartialTrustVisibleAssemblies to create AppDomain. Source = System.ServiceModel.DomainServices.Server TypeName = "" Stack Trace: at System.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetForeignKeyMembers () in System.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetTypeDescriptor (type objectType, object instance) in System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties () in System.ComponentModel.TypeDescriptor.GetProperties (TypeTomTerService.Service.Service.Service.Service.Service.Service ServiceModel.DomainServices.Server.DomainServiceDescription.AddQueryMethod (DomainOperationEntry method) in System.ServiceModel.DomainServices.Server.DomainServiceDescription.Initialize () in System.ServiceModel.DomainServices.Server.DomainCerviceDvice tion (type domainServiceType) in System.ServiceModel.DomainServices.Server.DomainServiceDescription. <> c_DisplayClass8.b_7 (Type Type) in System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey key, Func 2 valueFactory) in System.ServiceModel.DomainServices.Server.DomainServiceDescription.GetDescription (Type domainService.DerviceTervicepemepevicepemepevicepemepevicepemepevicepemevicepemeperevicevicemeyerpemevicevicemeyerpeimevice .Hosting.DomainServiceHost..ctor (type domainServiceType, Uri [] baseAddresses) in PartialTrustTest.Program.Main (String [] args) in D: \ Users \ carlucci \ Documents \ My Dropbox \ My Dropbox \ Way2 \ PartialTrustTest \ PartialTrustTest \ Program.cs: line 10 in System.AppDomain._nExecuteAssembly (assembly RuntimeAssembly, String [] args) in System.AppDomain.nExecuteAssembly (assembly RuntimeAssembly, String [] args) in System.Runtime.Hosting.ManifestRunner.Run (Boolean check) in System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly () in System.Runtime.Hosting.ApplicationActivator.CreateInstance (ActivationContext activationContext, String [] activationCus tomData) in System.Runtime.Hosting.ApplicationActivator.CreateInstance (ActivationContext activationContext) in System.Activator.CreateInstance (ActivationContext activationContext) in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDreadHreadProoneZone.readgonezone.readgonezone.readgonezone.readgonezone.readgonezone.readgonezone in System.Threading.ExecutionContext.Run (ExecutionContext executeContext, ContextCallback callback, object state, Boolean ignoreSyncCtx) in System.Threading.ExecutionContext.Run (ExecutionContext executeContext, ContextCallback callback, object state) in System.ThreadingTh

readHelper.ThreadStart () InnerException:


I tried to add System.ComponentModel.DataAnnotations to APTCA but did not succeed :(

I changed my application to full trust, but did not have time :(

Any idea?

+4
source share
2 answers

Not only this is possible, but also the complete list of codes that RIA provides with OData, which is consumed by Excel PowerPivot. Remember that you must turn off the visual studio process or just run without debugging. When using PowerPivot, be sure to enable trailing slash so that your URL is: 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(); } } } 
+1
source

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 out the * .config of your exe file, as I remember that there were some settings related to IIS that you should remove.

Also in the project properties in VS, open the Debug tab and uncheck the Enable Visual Studio Hosting Process box.

0
source

Source: https://habr.com/ru/post/1332365/


All Articles