无法在类库应用程序中使用WCF服务

无法在类库应用程序中使用WCF服务,wcf,Wcf,我有一个在IIS 8.5上运行的WCF服务。我在Windows窗体项目和控制台应用程序项目中使用并测试了该服务,效果很好!但我无法使用Visual Studio 2013中类库项目中的web服务 在ServiceModel客户端配置部分中找不到引用约定“bindsigner.bindSinalRService”的默认终结点元素。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此约定匹配的端点元素。 我查看了Windows窗体项目(有效)和类库项目的配置文件,但找不到区别。我做错了

我有一个在IIS 8.5上运行的WCF服务。我在Windows窗体项目和控制台应用程序项目中使用并测试了该服务,效果很好!但我无法使用Visual Studio 2013中类库项目中的web服务

在ServiceModel客户端配置部分中找不到引用约定“bindsigner.bindSinalRService”的默认终结点元素。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此约定匹配的端点元素。

我查看了Windows窗体项目(有效)和类库项目的配置文件,但找不到区别。我做错了什么

该服务的web.Config是:

<configuration>
    <system.web>
      <compilation targetFramework="4.0" />
    </system.web>

    <system.serviceModel>
                   <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <customBinding>
                <binding name="bindSignalRService.Web.bindSinalRService.customBinding0">
                    <binaryMessageEncoding />
                    <httpTransport />
                </binding>
                               </customBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
            multipleSiteBindingsEnabled="true" />
        <services>
            <service name="bindSignalRService.Web.bindSinalRService">
                <endpoint address="" binding="customBinding" bindingConfiguration="bindSignalRService.Web.bindSinalRService.customBinding0"
                    contract="bindSignalRService.Web.bindSinalRService" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
    </system.serviceModel>
</configuration>

Windows窗体中的app.config(这个很好用!)应用程序:


但是,当我尝试在类库应用程序中使用WCF服务时,出现了错误:
在ServiceModel客户端配置部分中找不到引用约定“bindsigner.bindSinalRService”的默认终结点元素。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此合约匹配的端点元素。已解决:感谢您尝试帮助我。我真的很难做到这一点(投入了很多很多时间)

当您在库应用程序中使用Web服务时(无论您在哪里使用库),必须将app.config文件的端点和绑定部分从库复制到要使用库的项目中的(Web/app.config)(如果有问题,请纠正我)

就我而言,我复制了:

<system.serviceModel>
    <bindings>
        <customBinding>
            <binding name="bind">
                <binaryMessageEncoding />
                <httpTransport />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:49904/bindSinalRService.svc"
            binding="customBinding" bindingConfiguration="bind" contract="bindSignalRService.Web.bindSinalRService"
            name="myEnpointName" />
    </client>
</system.serviceModel>


我得到的错误是粗体和中间的错误。在什么情况下会出现该错误。我想你是说你有个例外。请发布完整的异常,包括堆栈跟踪和任何内部异常。出于故障排除的目的,执行此操作的简单方法是捕获异常,然后发布
ex.ToString()
的结果。您在哪个过程中托管类库?看起来托管库的应用程序的配置尚未使用上面的配置更新。System.InvalidOperationException:在ServiceModel客户端配置部分中找不到名为“Hola1”和约定为“BindSignalService.Web.bindSinalRService”的端点元素。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此名称匹配的端点元素。事实上,对于类库来说,这始终是正确的。放置在类库app.config中的任何内容都需要移动到消费应用程序的app.config或web.config中。从第一天开始就是这样。考虑到可能有不止一个用户的库,并且特定于库的任何配置对于每个消费者可能是不同的。
<system.serviceModel>
    <bindings>
        <customBinding>
            <binding name="bind">
                <binaryMessageEncoding />
                <httpTransport />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:49904/bindSinalRService.svc"
            binding="customBinding" bindingConfiguration="bind" contract="bindSignalRService.Web.bindSinalRService"
            name="myEnpointName" />
    </client>
</system.serviceModel>