繁体   English   中英

WCF中的c#绑定错误

[英]c# binding error in WCF

尝试访问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。 已启用匿名访问(安全实施将在稍后进行)。

我们非常感谢任何帮助,因为这是我们项目的完整展示。 我已经在网上搜索了这个问题的解决方案,但似乎与我的特定设置没什么关系。

尝试启用对服务的跟踪,以检查测试/生产环境中出现故障的原因。 要启用跟踪,请检查此链接

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

所以对我来说,解决这个问题的方法是根据你的一些建议删除mex绑定。 我还从config中的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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM