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

标签 wcf

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

在 ServiceModel 客户端配置部分中找不到引用协定“bindSignalR.bindSinalRService”的默认端点元素。这可能是因为没有找到您的应用程序的配置文件,或者因为在客户端元素中找不到与此契约(Contract)匹配的端点元素。

我查看了 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(这个工作正常!)app:

<configuration>
    <configSections>
    </configSections>
    <system.serviceModel>
        <bindings>
            <customBinding>
                                   <binding name="CustomBinding_bindSinalRService">
                    <binaryMessageEncoding />
                    <httpTransport />
                </binding>
            </customBinding>
        </bindings>
        <client>
          <endpoint address="http://slascvm042:49904/bindSinalRService.svc"
                binding="customBinding" bindingConfiguration="CustomBinding_bindSinalRService"
                contract="bindNewEventService.bindSinalRService" name="CustomBinding_bindSinalRService" />

        </client>
    </system.serviceModel>
</configuration>

但是当我尝试在类库应用程序中使用 WCF 服务时,出现错误: 在 ServiceModel 客户端配置部分中找不到引用协定“bindSignalR.bindSinalRService”的默认端点元素。这可能是因为没有找到您的应用程序的配置文件,或者因为在客户端元素中找不到与此契约(Contract)匹配的端点元素。

最佳答案

已解决:感谢您尝试帮助我。我对此感到非常困难(投入了很多很多时间)。

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

就我而言,我复制了:

<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>

关于wcf - 无法在类库应用程序中使用 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28177317/

相关文章:

.net-3.5 - WCF 服务与 Windows 服务

c# - WCF 调试记录敏感信息

wcf - 使用 makecert 命令行时证书将存储在系统中的位置

c# - WCF ReplyAction ="*"破坏元数据

c# - WCF 的凭证委托(delegate)问题

c# - 是否可以使用库中的类型创建 DataContract?

c# - 使用 WCF 访问 SQL Server : Timeout

c# - 如何使用变量作为类型

javascript - 使用 JavascriptCallbackBehavior 时如何抛出带有 HTTP 错误代码的 WebFaultException?

c# - 通过工作线程的异步接口(interface)使用 WCF 服务,如何确保从客户端发送事件 "in order"