通过 WCF RIA 服务公开 OData

发布于 2024-09-07 18:43:05 字数 999 浏览 7 评论 0原文

我创建了一个新的 Silverlight 应用程序,因此我有一个名为“SilverlightOnLineChess.Web”的 Web 项目和名为“SilverlightOnlineChess.Client”的 Silverlight 应用程序。在此解决方案中,我创建了一个名为“SilverlightOnlineChess.Data”的新 WCF RIA 服务类库,并在此过程中创建了名为“SilverlightOnlineChess.Data.Web”的关联 Web 项目。我已在“SilverlightOnlineChess.Data.Web”项目中创建了必要的实体数据模型和域服务类,并确保选中了“Expose OData 端点”。

通过应用程序查看数据一切正常。但是,如果我尝试点击 url 来查看 OData 返回的内容,如下所示: "http://localhost:49771/SilverlightOnlineChess-Data-Web -OnlineChessService.svc/OData/”它不知道这个网址是什么。仅当我在主 Web 项目“SilverlightOnLineChess.Web”而不是“SilverlightOnLineChess.Data.Web”中创建服务和实体模型时,它才有效。

所以现在如果我输入如下网址:

http://localhost :49771/SilverlightOnlineChess-Web-OnlineChessService.svc/OData/”,它会带回元数据。

有什么想法吗?

I've created a new Silverlight application, so I have a web project called "SilverlightOnLineChess.Web" and the Silverlight app called "SilverlightOnlineChess.Client". In this solution I've created a new WCF RIA Services class library called "SilverlightOnlineChess.Data", and in doing so it creates the associated web project called "SilverlightOnlineChess.Data.Web". I've created the necessary Entity Data Model and the domain service classes in the "SilverlightOnlineChess.Data.Web" project and made sure I checked the "Expose OData endpoint".

Everything works fine and dandy to view data via the app. However, if I try to hit the url to see what the OData brings back as in:
"http://localhost:49771/SilverlightOnlineChess-Data-Web-OnlineChessService.svc/OData/" it doesn't know what this url is. It only works if I create the services and entity model in the main web project "SilverlightOnLineChess.Web" and not the "SilverlightOnLineChess.Data.Web".

So now if I enter the url as in:

"http://localhost:49771/SilverlightOnlineChess-Web-OnlineChessService.svc/OData/", it brings back the metadata.

Any ideas?

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

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

发布评论

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

评论(2

短暂陪伴 2024-09-14 18:43:05

服务的 URL 如下所示:

域服务的命名空间 + 类型名称,其中点由破折号替换,后跟 .svc/OData/。

之后,您需要通过在

[Query(IsDefault = true)]

要公开的查询上方添加来向 OData 公开查询。

The URL of the Service occurs as follows:

Namespace + typename for the domain service with dots replaced by dashes followed by .svc/OData/.

After this you need to expose queries to OData by adding

[Query(IsDefault = true)]

above your queries you want to expose.

差↓一点笑了 2024-09-14 18:43:05

要公开 OData 端点,您需要确保 web.Config 中具有以下内容:

<system.serviceModel>
    <domainServices>
      <endpoints>
        <add name="OData" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </endpoints>
    </domainServices>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />    
  </system.serviceModel>

您还需要确保引用以下 DLL:

System.ServiceModel.DomainServices.Hosting.OData
C:\Program Files\Microsoft SDKs\RIA Services\v1.0\Libraries\Server\System.ServiceModel.DomainServices.Hosting.OData.dll

您可以通过查看来确保您正在寻找 OData 服务的正确 URL选择“显示所有文件”的客户端项目。转到Generate_Code\ProjectName.Web.g.cs。查找 Service.svc。这将是 OData 服务的根 URI。如果您将域服务放在 Service 文件夹下,则该文件夹将为 Service/YourServiceName.svc/OData/。

To expose an OData endpoint, you need to make sure you have the following in your web.Config:

<system.serviceModel>
    <domainServices>
      <endpoints>
        <add name="OData" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </endpoints>
    </domainServices>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />    
  </system.serviceModel>

You also need to make sure you are referening the following DLLs:

System.ServiceModel.DomainServices.Hosting.OData
C:\Program Files\Microsoft SDKs\RIA Services\v1.0\Libraries\Server\System.ServiceModel.DomainServices.Hosting.OData.dll

You can make sure you're looking for the right URL to your OData service by looking in your client-side project with Show All Files selected. Go to Generated_Code\ProjectName.Web.g.cs. Do a find for Service.svc. That will be the root URI of your OData service. If you put your domain service under a Service folder it will be Service/YourServiceName.svc/OData/.

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