简体   繁体   English

WCF中的c#绑定错误

[英]c# binding error in WCF

I am getting the following error when trying to access a WCF service. 尝试访问WCF服务时出现以下错误。

Could not find a base address that matches scheme http for the endpoint with binding MetadataExchangeHttpBinding. 无法通过绑定MetadataExchangeHttpBinding找到与端点的方案http匹配的基址。 Registered base address schemes are [https]. 注册的基地址方案是[https]。

Here's my config 这是我的配置

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

And here's my .scv file 这是我的.scv文件

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

To give some more background that may or may not be helpful 提供一些可能有用或可能没有帮助的背景知识

  • The service works fine in our DEV environment. 该服务在我们的DEV环境中正常运行。 This error is only occurring in our TEST and PROD environments. 此错误仅发生在我们的TEST和PROD环境中。 The only discernable difference between environments that i am aware of is that TEST and PROD are using a load balancer. 我所知道的环境之间唯一可辨别的差异是TEST和PROD正在使用负载均衡器。
  • The service is hosted in IIS 5.1 on all environments 该服务在所有环境中的IIS 5.1中托管
  • The service has been written in dot.net 3.5 and is activated by a WebServiceHost factory 该服务已在dot.net 3.5中编写,并由WebServiceHost工厂激活
  • I have not specified https anywhere in my config file 我没有在配置文件中的任何地方指定https
  • SSL has NOT been enabled in IIS on any of the environments. 在任何环境中,IIS都未启用SSL。 Anonymous access has been enabled (security implementation will come later on). 已启用匿名访问(安全实施将在稍后进行)。

Any help would be much appreciated as this is a complete show stopper for our project. 我们非常感谢任何帮助,因为这是我们项目的完整展示。 I have throurghly searched the web for solutions to this problem, but nothing seems to relate to my my particular set up. 我已经在网上搜索了这个问题的解决方案,但似乎与我的特定设置没什么关系。

Try enabling tracing on your service to check why things fail in your test/production environment. 尝试启用对服务的跟踪,以检查测试/生产环境中出现故障的原因。 To enable tracing check this link 要启用跟踪,请检查此链接

Are you sure that the MyWcfServiceHostFactory doesnt have any code related to configuration (ie building configuration via c# code) 你确定MyWcfServiceHostFactory没有任何与配置相关的代码(即通过c#代码构建配置)

So for me, the fix for this issue was to remove the mex binding as per some of your suggestions. 所以对我来说,解决这个问题的方法是根据你的一些建议删除mex绑定。 I also removed the servicemetadata section from the DefaultBehavior in config. 我还从config中的DefaultBehavior中删除了servicemetadata部分。

This fix only hides the original issue as I still have no idea why the mex binding was registered as https. 此修复程序仅隐藏原始问题,因为我仍然不知道为什么mex绑定被注册为https。 But I can now consume my web service, even if i can't retrieve the metadata from it - that's not a problem in my case. 但我现在可以使用我的Web服务,即使我无法从中检索元数据 - 这在我的情况下也不是问题。

Here's the corrected config 这是更正后的配置

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