WCF中的c#绑定错误

本文关键字:错误 绑定 中的 WCF | 更新日期: 2023-09-27 18:15:00

尝试访问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中托管
  • 该服务是用。net 3.5编写的,并通过WebServiceHost工厂
  • 我没有指定https在我的配置文件
  • SSL尚未在任何环境的IIS中启用。匿名访问已启用(稍后将实现安全)。

任何帮助将不胜感激,因为这是我们项目的一个完整的节目。我已经在网上彻底搜索了这个问题的解决方案,但似乎没有什么与我的特殊设置有关。

WCF中的c#绑定错误

所以对我来说,这个问题的解决方案是根据您的一些建议删除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>

尝试在您的服务上启用跟踪,以检查在测试/生产环境中失败的原因。要启用跟踪,请检查链接

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