代码之家  ›  专栏  ›  技术社区  ›  Duncan Bayne

如何从windows服务访问wcf-ria服务?

  •  7
  • Duncan Bayne  · 技术社区  · 14 年前

    我有一个运行正常的Silverlight4应用程序(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 我看到以下内容:

    您已经创建了一个服务。测试 此服务,您需要创建 一个客户并用它调用 服务。你可以用 命令行中的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>
    

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

    元素system.servicemodel具有 无效的子元素domainservices。

    其次,前面提到的silverlight应用程序停止工作,可能是因为这个更改破坏了底层web服务。

    第三,看起来system.servicemodel.domainservices.hosting程序集实际上并不包含soapxmlendpointfactory类型;如果在将上述内容添加到web.config之后尝试浏览到服务,则会看到:

    无法加载类型 'system.servicemodel.domainservices.hosting.SoapXmlEndpointFactory' 从程序集 'system.servicemodel.domainservices.hosting,' 版本=4.0.0.0,区域性=中性, publickeytoken=31bf3856ad364e35'。

    如果我使用reflector检查程序集,我会看到它包含domainserviceendpointfactory和poxbinaryendpointfactory类型,但没有soapxmlenendpointfactory。

    有人能告诉我该怎么做吗?我不敢相信在silverlight应用程序之外的其他应用程序中简单地使用wcf ria服务会这么困难!

    4 回复  |  直到 14 年前
        1
  •  2
  •   Doobi    14 年前
        2
  •  4
  •   SteveC    13 年前

    而不是。。。

    system.servicemodel.domainservices.hosting系统

    使用程序集…

    Microsoft.ServiceModel.domainServices.hosting

    来自wcf ria服务工具包。它包含类型 SoapXmlEndpointFactory .

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

        3
  •  1
  •   SteveC    13 年前

    这个 SoapXmlEndpointFactory 类是

    Microsoft.ServiceModel.domainServices.hosting

    程序集,它包含在Silverlight工具包中。

    here

        4
  •  1
  •   Mohnkuchenzentrale    12 年前
    <sectionGroup name="system.serviceModel">
      <section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowDefinition="MachineToApplication" requirePermission="false" />
    </sectionGroup>
    

    在configSections中声明。正确地包含分区组很重要