c# - 如何从 Windows 服务访问 WCF RIA 服务?

标签 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" %>

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

You have created a service. To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax: 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>

首先,Intellisense 提示标签的存在,说:

The element system.ServiceModel has invalid child element domainServices.

其次,上述 Silverlight 应用程序停止工作,可能是因为此更改破坏了底层 Web 服务。

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

Could not load type 'System.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory' from assembly 'System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

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

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

最佳答案

而不是......

System.ServiceModel.DomainServices.Hosting

使用程序集...

Microsoft.ServiceModel.DomainServices.Hosting

来自 WCF RIA 服务工具包。它包含 SoapXmlEndpointFactory 类型。

默认位置是...%Program Files%\Microsoft SDKs\RIA Services\v1.0\Toolkit\Libraries\Server

关于c# - 如何从 Windows 服务访问 WCF RIA 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2799637/

相关文章:

php - 如何检查服务器是否能够处理 SOAP 请求

c# - 如何对List<Entity>进行排序?

data-annotations - 使用 RIA 服务自定义数据注释

c# - 为什么这个 Entity Framework 数据库更新这么慢?

c# - @onkeypress 没有获取文本输入框的更新值?

android - 使用来自 Android 的 SOAP 调用 Magento api 时的 XMLPull 解析器异常

apache-flex - 在 Flex 4 中使用 HTTPS Web 服务

c# - 如何在运行时在 C# 中设置类型 TSomething?

c# - 如何将邮件移动到单独的文件夹中

c# - MS Word 中的语法高亮显示