在 RIA 服务客户端代码生成中排除服务

发布于 2024-10-23 20:16:37 字数 855 浏览 2 评论 0原文

我有一个使用 RIA Services 1.0 SP1 的 Silverlight 4 应用程序。

在托管 Silverlight 应用程序的 Web 应用程序中,我有一些 RIA 服务和一个供其他使用者(不是 Silverlight 应用程序)使用的纯 WCF 服务。

RIA 服务正在尝试(但失败)在 Silverlight 应用程序中生成客户端代理代码以调用 WCF 服务。我不需要从 Silverlight 调用该服务。

如何防止 RIA 服务生成该服务的客户端代码?
我有一个可以用来忽略该服务的属性吗?

编辑
我假设 RIA 服务会尝试生成代理,但我不确定。这里有更多信息:

我有以下编译警告:

服务“MyNamespace.MyWcfService”的客户端代理生成失败:错误:地址“http://localhost/Service”处的端点“WSHttpBinding_SurveyCentreWcfService”与 Silverlight 4 不兼容。正在跳过.. 。

我没有在我的 Silverlight 应用程序中手动添加任何服务引用,但 WCF RIA 服务链接是在项目属性中设置的

我的服务类如下所示:

[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(Namespace = "http://www.xxx.com/services/")]
public class MyWcfService
{
    ...
}

I have a Silverlight 4 application using RIA Services 1.0 SP1.

In the web application that hosts the Silverlight app I have a few RIA services and a pure WCF service that is there for other consumers (not the Silverlight app).

RIA Services is attempting (and failing) to generate client proxy code in the Silverlight app to call the WCF service. I do not need to call that service from Silverlight.

How can I prevent RIA Services from generating the client code for that service?
I there an attribute I can use to ignore that service?

EDIT
I was assuming that it would be RIA Services trying the generate the proxy, but I'm not sure. Here's more info:

I have the following compilation warning:

Client proxy generation for service 'MyNamespace.MyWcfService' failed: Error: Endpoint 'WSHttpBinding_SurveyCentreWcfService' at address 'http://localhost/Service' is not compatible with Silverlight 4. Skipping...

I haven't manually added any Service Reference in my Silverlight application, but the WCF RIA Services Link is set in the project properties.

My service class looks like this:

[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(Namespace = "http://www.xxx.com/services/")]
public class MyWcfService
{
    ...
}

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

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

发布评论

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

评论(2

伴我老 2024-10-30 20:16:37

据我所知,Ria 只从 DomainService 类生成代码。你的WCF服务是继承自DomainService吗?

这听起来像是 silverlight 端的代理代码生成器。 RIA 服务不需要 Web 参考。如果您在 silverlight 项目中有 Web 引用,请将其删除。

此外,您还可以在 build.log 文件中看到哪些代理生成工具正在查看哪些文件。这有点难以解读,但可能对解决您的问题有所帮助。

可能性很小,但请确保 silverlight 应用程序中的任何文件都没有设置自定义工具。

Ria, as far as I knew, only generated code from DomainService classes. Is your WCF Service inheriting from DomainService?

This kind of sounds like it could be the proxy code generator on the silverlight side. RIA services doesn't require a web reference. If you have a web reference in the silverlight project, remove it.

Also, you can see in the build.log file which proxy generation tools are looking at what files. It's a little hard to decipher, but it might help with your issue.

Very unlikely, but make sure no custom tools are set on any files in your silverlight application.

尘世孤行 2024-10-30 20:16:37

您可以使用 DomainServiceHostFactory 来限制哪些请求可以启动哪些服务,如下所示:

 public class RestrictedServiceHost : DomainServiceHostFactory
 {
    private static List<string> _allowedSchemes;

    static RestrictedServiceHost ()
    {
        RestrictedProtocolServiceHost._allowedSchemes = new List<string>();
        RestrictedProtocolServiceHost._allowedSchemes.Add( Uri.UriSchemeHttp );
        RestrictedProtocolServiceHost._allowedSchemes.Add( Uri.UriSchemeHttps );
    }

    protected override ServiceHost CreateServiceHost ( Type serviceType, Uri[] baseAddresses )
    {
        baseAddresses = baseAddresses.Where( uri => RestrictedProtocolServiceHost._allowedSchemes.Contains( uri.Scheme ) ).ToArray();
            return base.CreateServiceHost( serviceType, baseAddresses );
    }
 }

如果您的 web.config 如下所示,则可以使用它:

 <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
      <serviceActivations>
        <add service="RIA.FooDomainService"
             relativeAddress="Services/FooProject-FooDomainService.svc"
             factory="YourWebProject.RestrictedProtocolServiceHost"/>
      </serviceActivations>
    </serviceHostingEnvironment>

You could look to use the DomainServiceHostFactory to restrict what requests can initiate what services, an example below:

 public class RestrictedServiceHost : DomainServiceHostFactory
 {
    private static List<string> _allowedSchemes;

    static RestrictedServiceHost ()
    {
        RestrictedProtocolServiceHost._allowedSchemes = new List<string>();
        RestrictedProtocolServiceHost._allowedSchemes.Add( Uri.UriSchemeHttp );
        RestrictedProtocolServiceHost._allowedSchemes.Add( Uri.UriSchemeHttps );
    }

    protected override ServiceHost CreateServiceHost ( Type serviceType, Uri[] baseAddresses )
    {
        baseAddresses = baseAddresses.Where( uri => RestrictedProtocolServiceHost._allowedSchemes.Contains( uri.Scheme ) ).ToArray();
            return base.CreateServiceHost( serviceType, baseAddresses );
    }
 }

Which you then use if your web.config like:

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