4

Windows サービス インターフェイスとして Silverlight を使用したいと考えています。そのために、カスタム 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.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' は、現在の AppDomain で有効になっていない条件付き APTCA アセンブリです。このアセンブリを部分信頼コードまたはセキュリティ透過コードで使用できるようにするには、アセンブリ名「System.ComponentModel.DataAnnotations」を追加してください。PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9' to the the PartialTrustVisibleAssemblies list when creating the AppDomain. Source=System.ServiceModel.DomainServices.Server TypeName="" StackTrace: System.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetForeignKeyMembers() で System.ServiceModel.DomainServices.Server.DomainTypeDescriptionProvider.GetTypeDescriptor (型 objectType、オブジェクト インスタンス) で System .ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.System.Collections.Concurrent.ConcurrentDictionary のDisplayClass8.b _7(Type タイプ)2.GetOrAdd(TKey key, Func2 valueFactory) System.ServiceModel.DomainServices.Server.DomainServiceDescription.GetDescription(Type domainServiceType) で System.ServiceModel.DomainServices.Hosting.DomainServiceHost..ctor(Type domainServiceType, Uri[] baseAddresses) で PartialTrustTest.Program.Main(String[ ] args) in D:\Users\carlucci\Documents\My Dropbox\My Dropbox\Way2\PartialTrustTest\PartialTrustTest\Program.cs:10 行目 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain .nExecuteAssembly(RuntimeAssembly アセンブリ、String[] args) で System.Runtime.Hosting.ManifestRunner.Run(Boolean 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 コールバック、オブジェクト状態、ブール値の ignoreSyncCtx) System.Threading.ExecutionContext.Run で (ExecutionContext 実行コンテキスト、ContextCallback コールバック、オブジェクト状態) System.Threading.Th でMicrosoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() での CreateInstance(ActivationContext activationContext) System.Threading.ThreadHelper.ThreadStart_Context(オブジェクト状態) で System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback コールバック、オブジェクト状態、Boolean ignoreSyncCtx) System.Threading.ExecutionContext.Run (ExecutionContext executionContext、ContextCallback コールバック、オブジェクト状態) で System.Threading.ThMicrosoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() での CreateInstance(ActivationContext activationContext) System.Threading.ThreadHelper.ThreadStart_Context(オブジェクト状態) で System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback コールバック、オブジェクト状態、Boolean ignoreSyncCtx) System.Threading.ExecutionContext.Run (ExecutionContext executionContext、ContextCallback コールバック、オブジェクト状態) で System.Threading.ThSystem.Threading.Th での ExecutionContext.Run (ExecutionContext 実行コンテキスト、ContextCallback コールバック、オブジェクト状態)System.Threading.Th での ExecutionContext.Run (ExecutionContext 実行コンテキスト、ContextCallback コールバック、オブジェクト状態)

readHelper.ThreadStart() InnerException:


System.ComponentModel.DataAnnotations を APTCA に追加しようとしましたが、成功しませんでした:(

アプリケーションを完全な信頼で実行するように変更しましたが、成功しませんでした:(

何か案が?

4

2 に答える 2

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();
              }
       }
}
于 2011-11-04T15:22:18.970 に答える
0

IIS なしで RIA サービスを使用できます。開く前にドメイン サービスを構成します。

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

exe ファイルの *.config も確認してください。IIS に関連するいくつかの設定を削除する必要があることを覚えています。

また、VS のプロジェクト プロパティで、[デバッグ] タブを開き、[Visual Studio ホスティング プロセスを有効にする] のチェックを外します。

于 2011-05-18T08:21:23.157 に答える