动态托管 WCF RIA 服务(不引用它)

发布于 2024-12-19 07:44:55 字数 2478 浏览 2 评论 0原文

请问,我有以下问题: 我正在尝试动态加载 WCF RIA 服务(Silverlight 应用程序的 DDL 和 DAL)。
我有主要的应用程序维护授权、身份验证等。该应用程序是使用 Prism 库实现的 - 高度模块化,但不幸的是,由于引用了紧密耦合的 RIA 服务库,因此不可能根据客户的要求切换模块,而无需重新编译整个解决方案并导致自动生成的代码出现问题。它托管在 IIS (IIS Express) 中。
我想做的是删除主网页应用程序中对自定义模块的引用,动态加载模块并创建必要的端点。 我的第一个方法是在 Web.config 中定义服务:

    <services>
        <service name=PatientRegistry.PatientRegistryDomainService"
        behaviorConfiguration="RIAServiceBehavior">
            <endpoint address="" binding="wsHttpBinding"
            contract="PatientRegistryDomainService" />
            <endpoint address="/soap"
            binding="basicHttpBinding"
            contract="PatientRegistryDomainService" />
            <endpoint address="/binary"
            binding="customBinding"
            bindingConfiguration="BinaryHttpBinding"
            contract="PatientRegistryDomainService" />
        </service>

    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="RIAServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <customBinding>
            <binding name="BinaryHttpBinding">
                <binaryMessageEncoding />
                <httpTransport />
            </binding>
        </customBinding>
    </bindings>

问题是,因为没有引用它,所以没有加载必要的程序集。

然后我尝试在代码中加载程序集,从导出类型(_types)列表中获取DomainServiceType并使用DomainServiceHost:

    Type _svctype = null;
foreach (Type _T in _types)
{
    if (IsSubclassOfRawGeneric(typeof(DomainService), _T))
    {
        _svctype = _T;
        break;
    }
}
DomainServiceHost host = new DomainServiceHost(_svctype /*, BaseUri*/);
host.Open();

这种方法在我之前对自托管RIA的尝试中遇到同样的问题时失败了:AspNetCompatibilityModeAttribute:
此服务需要 ASP.NET 兼容性,并且必须托管在 IIS 中。要么在 IIS 中托管该服务,并在 web.config 中启用 ASP.NET 兼容性,要么将 AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode 属性设置为“Required”以外的值。
我尝试通过添加来设置域服务上的属性

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

,但没有效果。我拼命谷歌搜索了很长一段时间,但没有成功。 您能帮我指出如何加载未引用的 RIA 服务服务器的正确方向吗?

PS我使用的是Silverlight 5,VS2010

Please, I have the following problem:
I'm trying to dynamically load a WCF RIA service (DDL and DAL for Silverlight app).
I have main application maintaining authorization, authentication and so on. The app is implemented using Prism libraries - highly modular, but unfortunately because of referencing the RIA service library tihgtly coupled, so it is impossible to switch modules depending on customers requirements without recompiling whole solution and causing trouble with autogenerated code. It is hosted in IIS (IIS Express).
What I'm trying to do is to remove the reference to custom module in the main Webpage app, load the module dynamically and create necesary endpoints.
My first approach was to define the service in Web.config:

    <services>
        <service name=PatientRegistry.PatientRegistryDomainService"
        behaviorConfiguration="RIAServiceBehavior">
            <endpoint address="" binding="wsHttpBinding"
            contract="PatientRegistryDomainService" />
            <endpoint address="/soap"
            binding="basicHttpBinding"
            contract="PatientRegistryDomainService" />
            <endpoint address="/binary"
            binding="customBinding"
            bindingConfiguration="BinaryHttpBinding"
            contract="PatientRegistryDomainService" />
        </service>

    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="RIAServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <customBinding>
            <binding name="BinaryHttpBinding">
                <binaryMessageEncoding />
                <httpTransport />
            </binding>
        </customBinding>
    </bindings>

Trouble was, that because it wasn't referenced, the necesary assembly wasn't loaded.

Then I tried to load the assembly in code, get the DomainServiceType from list of exported types (_types) and use DomainServiceHost:

    Type _svctype = null;
foreach (Type _T in _types)
{
    if (IsSubclassOfRawGeneric(typeof(DomainService), _T))
    {
        _svctype = _T;
        break;
    }
}
DomainServiceHost host = new DomainServiceHost(_svctype /*, BaseUri*/);
host.Open();

This approach failed on the wery same trouble all my previous attempts on selfhosting RIA: AspNetCompatibilityModeAttribute:
This service requires ASP.NET compatibility and must be hosted in IIS. Either host the service in IIS with ASP.NET compatibility turned on in web.config or set the AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode property to a value other than Required.
I've tried to set the attribute on the domain service by adding

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

but it had no effect. I'm quite desperately googling for quite a long time, but to no success.
Could you please kick me in the right direction on how to load unreferenced RIA service server?

P.S. I'm on Silverlight 5, VS2010

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

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

发布评论

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

评论(1

失而复得 2024-12-26 07:44:55

您是否尝试过将其包含在您的 web.config 中?

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

Have you tried to include this in your web.config?

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