【问题标题】:How to include the assembly name in the service type declaration in web.config in wcf?如何在 wcf 的 web.config 中的服务类型声明中包含程序集名称?
【发布时间】:2015-06-23 21:04:15
【问题描述】:

我正在从一本 WCF 书中实现这一点。我从书中读到以下内容:

网站配置文件 (web.config) 通常会列出您想要公开为服务的类型。 如果服务类型来自未引用的程序集,则需要使用完全限定的类型名称,包括程序集名称:

< system.serviceModel > 
    < services > 
        < service name = "MyNamespace.MyService" > ... </ service > 
    </ services > 
</ system.serviceModel >

使用它,我在我的服务项目的 web.config 中编写了以下内容:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
      <serviceActivations>
        <add relativeAddress="MyService.svc" service="Service"/>
        <add relativeAddress="MyAssemblyService.svc" service="WcfServiceLibrary1.Service1"/>
      </serviceActivations>
    </serviceHostingEnvironment>
    <services>
      <service name="Service">
      </service>
      <service name="WcfServiceLibrary1.Service1">
      </service>
    </services>

在这里,如果我在我的 WCF 服务项目中引用服务程序集,我可以访问该服务,但如果我省略对服务程序集的引用,我会收到以下错误:

类型“WcfServiceLibrary1.Service1”,作为服务提供 ServiceHost 指令中的属性值,或在 配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 可以 找不到。

我已经搜索了很多找到,如何在“名称”属性中指定完整的限定服务名称,包括程序集,但似乎我没有使用正确的搜索关键字或者我们无法指定程序集名称在“名称”属性中。

我们可以在“name”属性中指定程序集名称吗?

【问题讨论】:

  • 我不确定我是否理解。当然,如果服务类型在那里,您需要引用程序集。
  • 请看我加粗的那一行。它说,您可以省略程序集引用,为此,您需要提及服务类型的完全限定名称,包括其程序集。对我来说,这在直觉上似乎是可行的,为了测试同样的,我正在这样做。
  • 谢谢你的大胆,我错过了那句话。 :) 尝试“WcfServiceLibrary1.Service1,YourLibraryAssembly”——这通常是格式。不知道它是否有效。

标签: wcf


【解决方案1】:

您好,您需要完全限定名称,以及 GAC 中的程序集 以下是如何获取完全限定名称的提示: https://msdn.microsoft.com/en-us/library/2exyydhb.aspx

这是在 GAC 中安装程序集的教程: http://net-informations.com/faq/framework/add-remove-assembly

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多