如何将SL / RIA作为WCF使用

时间:2013-03-14 13:50:26

标签: wcf-ria-services

使用VS2012并从SL业务应用程序项目开始,我补充说 EF模型Model1,删除了tt文件,将代码gen更改为Default并构建了项目。然后我添加了各种表的DomainService1。 OData未被选中。

启动应用程序时会显示可用的服务:

enter image description here

但是如果我们点击网址,我们希望看到XML,但它不起作用。追加?wsdl会导致XML被发送到浏览器,但我只是得到了插图页面。按照此页面的建议尝试使用svcutil会产生以下结果:

Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication 
Foundation, Version 4.0.30319.17929] Copyright (c) Microsoft Corporation.  
All rights reserved.

Attempting to download metadata from 'http://localhost:57880/Ria1-Web-DomainService1.sv
c?wsdl' using WS-Metadata Exchange or DISCO. Generating files...     
Warning: No code was generated. If you were trying to generate a client, this could be 
because the metadata documents did not contain any valid contracts or services or 
because all contracts/services were discovered to exist in /reference assemblies. 
Verify that you passed all the metadata documents to the tool.

Warning: If you would like to generate data contracts from schemas make sure to use
the /dataContractOnly option.

这似乎表明MEX端点没有正确设计,因此我的WCF书籍出来了,但他们认为应该在<system.serviceModel>和实际之间没有相关性那里:

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

我需要在配置中添加什么来公开元数据?

1 个答案:

答案 0 :(得分:0)

在准备这个问题时,我想知道当你指定OData时配置会发生什么。结果证明这是正确的问题。你明白了:

  <system.serviceModel>
    <serviceHostingEnvironment 
      aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <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>

  </system.serviceModel>

这给了我一些搜索字词。结合各种来源的信息导致了这一点:

<add name="Soap" 
     type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, 
     Microsoft.ServiceModel.DomainServices.Hosting, 
     Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

在我添加对此的引用之前完全无法工作:

Microsoft.ServiceModel.DomainServices.Hosting.EndPoints

随后一切都亮了起来,欢喜快乐。