【问题标题】:c# binding error in WCFc# WCF中的绑定错误
【发布时间】:2012-01-01 05:32:28
【问题描述】:

尝试访问 WCF 服务时出现以下错误。

找不到与绑定 MetadataExchangeHttpBinding 的端点的方案 http 匹配的基地址。注册的基地址方案是 [https]。

这是我的配置

<?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="true"/>
        <customErrors mode="Off"/>
      </system.web>

      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="DefaultHttpBinding"
                     maxBufferSize="655360"
                     maxReceivedMessageSize="655360">
            </binding>
          </basicHttpBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
          <baseAddressPrefixFilters>
            <add prefix="http://MySite.com/MyVirtualDir/"/>
          </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
        <services>
          <service behaviorConfiguration="DefaultBehavior"
                   name="MyWcfService">
            <endpoint address="http://MySite.com/MyVirtualDir/MyWcfService.svc"
                      binding="basicHttpBinding"
                      bindingConfiguration="DefaultHttpBinding"
                      contract="MyNamespace.IMyWcfService" />
            <endpoint address="mex"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="DefaultBehavior">
              <serviceMetadata httpGetEnabled="true"
                               policyVersion="Policy15"/>
              <serviceDebug httpHelpPageEnabled="true"
                            includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>

这是我的 .scv 文件

<%@ ServiceHost Language="C#" Debug="true" Service="MyWcfService" Factory="MyWcfServiceHostFactory"%>

提供更多可能有用也可能没有帮助的背景

  • 该服务在我们的 DEV 环境中运行良好。这个错误只是 发生在我们的 TEST 和 PROD 环境中。唯一可辨别的 我知道的环境之间的区别是 TEST 和 PROD 使用的是 负载平衡器。
  • 服务托管在所有环境中的 IIS 5.1 中
  • 该服务已在 dot.net 3.5 中编写并由 WebServiceHost 工厂
  • 我没有在我的配置文件中指定 https
  • 在任何环境中的 IIS 中都没有启用 SSL。匿名访问已启用(稍后将实施安全性)。

我们将不胜感激任何帮助,因为这是我们项目的完整展示。我已经在网上彻底搜索了此问题的解决方案,但似乎与我的特定设置无关。

【问题讨论】:

  • 您显然已经意识到这一点,但错误 really 表明以某种方式需要 https。但是由于该错误与元数据交换有关,您可以尝试检查是否禁用该功能可以让您访问该服务,然后稍后尝试消除元数据问题。也许您还应该检查元日期交换是否存在任何继承设置。
  • 如果您认为负载均衡器可能导致问题,那么您可以组织一个绕过它的测试吗?
  • 你也可以粘贴客户端配置吗?
  • 我确实尝试绕过负载均衡器并直接连接到两个节点,但得到了同样的错误。此外,这是第一个托管的 WCF 服务(目前所有其他 Web 服务都是 asmx),所以我认为没有任何其他的 mex 绑定配置被继承。
  • 顺便说一句。感谢您的快速和有益的答复。不幸的是,我必须经历一个漫长的变更控制过程才能部署到有问题的环境,而且我也没有任何直接访问它们的权限,因此我无法快速测试您的建议。接下来我将尝试禁用 mex 绑定。

标签: c# wcf web-config wcf-binding iis-5


【解决方案1】:

所以对我来说,解决这个问题的方法是根据您的一些建议删除 mex 绑定。我还从配置中的 DefaultBehavior 中删除了 servicemetadata 部分。

此修复仅隐藏了原始问题,因为我仍然不知道为什么 mex 绑定被注册为 https。但我现在可以使用我的 Web 服务,即使我无法从中检索元数据 - 这对我来说不是问题。

这是正确的配置

<?xml version="1.0"?>
    <configuration>
        <system.web>
            <compilation debug="true"/>
            <customErrors mode="Off"/>
        </system.web>

        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="DefaultHttpBinding"
                             maxBufferSize="655360"
                             maxReceivedMessageSize="655360">
                    </binding>
                </basicHttpBinding>
            </bindings>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
                <baseAddressPrefixFilters>
                    <add prefix="http://MySite.com/MyVirtualDir/"/>
                </baseAddressPrefixFilters>
            </serviceHostingEnvironment>
            <services>
                <service behaviorConfiguration="DefaultBehavior"
                         name="MyWcfService">
                    <endpoint address="http://MySite.com/MyVirtualDir/MyWcfService.svc"
                              binding="basicHttpBinding"
                              bindingConfiguration="DefaultHttpBinding"
                              contract="MyNamespace.IMyWcfService" />
                </service>
            </services>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="DefaultBehavior">
                        <serviceDebug httpHelpPageEnabled="true"
                                      includeExceptionDetailInFaults="true"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
        </system.serviceModel>
    </configuration>

【讨论】:

    【解决方案2】:

    尝试在您的服务上启用跟踪,以检查您的测试/生产环境中出现故障的原因。要启用跟踪检查此link

    您确定 MyWcfServiceHostFactory 没有任何与配置相关的代码(即通过 c# 代码构建配置)

    【讨论】:

    • 不幸的是,追踪没有提供更多细节。主机工厂确实添加了两种行为,一种是连接 Ioc 和 DI,另一种是将 FaultExceptions 更改为 HttpStatusCode200(需要将故障详细信息传递回 Silverlight 客户端)
    • 您的负载均衡器是否配置为仅使用 https 而不是 http 来建立安全性。值得尝试将流量直接转移到测试盒而不是负载均衡器,然后检查是否仍然出现异常。
    • 您是否尝试使用 https 而不是 http 访问您的网络服务。如果是这种情况,您的服务已配置为 http 而不是 https。如果您的情况是负载均衡器终止 SSL,那么这应该可以正常工作。
    • 更多的是相反,我正在尝试使用http,而不是https。基础设施人员向我保证,在该环境中未启用 SSL,无论是在负载平衡器还是任何节点上。我已经尝试过直接转移到测试框并得到同样的错误。
    • 您能否在您的测试环境中删除 mex 端点并检查您是否可以访问 Web 服务。您是否使用 IIS 来管理服务?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 2013-07-10
    相关资源
    最近更新 更多