如何从Windows服务访问WCF RIA服务?

Dun*_*yne 7 c# soap wcf-ria-services

我有一个正常运行的Silverlight 4应用程序(VS2010,SL4,WCF RIA,使用Cassini,64位Windows 7托管在我的开发盒上).在ClientBin目录中,我有一个描述我的服务的.svc文件:

<% @ServiceHost Service="MyApp.Services.MyService 
Factory="System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory" %>
Run Code Online (Sandbox Code Playgroud)

当我浏览到http:// localhost:52878/ClientBin/MyApp-Services-MyService.svc时,我看到以下内容:

您已创建了一项服务.要测试此服务,您需要创建一个客户端并使用它来调用该服务.您可以使用命令行中的svcutil.exe工具使用以下语法执行此操作:svcutil.exe http:// localhost:52878/ClientBin/MyApp-Services-MyService.svc?wsdl

我想从Windows服务应用程序访问该服务.我的理解是我需要启用SOAP端点才能实现这一点.所以,我将以下内容添加到我的web.config文件中:

<domainServices>
  <endpoints>
    <add name="soap" 
        type="System.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, 
        System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, 
        Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </endpoints>
</domainServices>
Run Code Online (Sandbox Code Playgroud)

首先,Intellisense抱怨标签的存在,说:

元素system.ServiceModel具有无效的子元素domainServices.

其次,前面提到的Silverlight应用程序停止工作,可能是因为此更改打破了底层Web服务.

第三,看起来System.ServiceModel.DomainServices.Hosting程序集实际上并不包含SoapXmlEndpointFactory类型; 如果我在将上面的内容添加到web.config后尝试浏览到该服务,我看到:

无法从程序集'System.ServiceModel.DomainServices.Hosting,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'加载类型'System.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory'.

如果我使用Reflector检查程序集,我看到它包含DomainServiceEndpointFactory和PoxBinaryEndpointFactory类型,但没有SoapXmlEndpointFactory.

有人可以让我知道我应该怎么做吗?我不敢相信在Silverlight应用程序之外的其他东西中简单地使用WCF RIA服务应该很难!

Doo*_*obi 2

你有没有尝试过只执行

svcutil.exe http://localhost:52878/ClientBin/MyApp-Services-MyService.svc?wsdl

或者,您是否安装了 RIA 服务工具包? http://www.microsoft.com/downloads/details.aspx?FamilyID=7b43bab5-a8ff-40ed-9c84-11abb9cda559&displaylang=en

SOAP 和 JSON 端点需要它