C# 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 使用的是 负载平衡器。
- 该服务在所有环境中托管在 IIS 5.1 中
- 该服务已在 dot.net 3.5 中编写,并由 WebServiceHost 工厂
- 我没有在配置文件中的任何位置指定 https
- SSL 尚未在任何环境的 IIS 中启用。已启用匿名访问(安全实施将在稍后实施)。
任何帮助将不胜感激,因为这对我们的项目来说是一个完全的阻碍。我已经在网上彻底搜索了此问题的解决方案,但似乎没有任何内容与我的特定设置相关。
I am getting the following error when trying to access a WCF service.
Could not find a base address that matches scheme http for the endpoint with binding MetadataExchangeHttpBinding. Registered base address schemes are [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
<%@ 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. This error is only
occurring in our TEST and PROD environments. The only discernable
difference between environments that i am aware of is that TEST and PROD are using a
load balancer. - The service is hosted in IIS 5.1 on all environments
- The service has been written in dot.net 3.5 and is activated by a
WebServiceHost factory - I have not specified https anywhere in my config file
- SSL has NOT been enabled in IIS on any of the environments. 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,对我来说,解决此问题的方法是根据您的一些建议删除 mex 绑定。我还从 config.xml 中的 DefaultBehavior 中删除了 servicemetadata 部分。
此修复仅隐藏了原始问题,因为我仍然不知道为什么 mex 绑定注册为 https。但我现在可以使用我的网络服务,即使我无法从中检索元数据 - 这对我来说不是问题。
这是更正后的配置
So for me, the fix for this issue was to remove the mex binding as per some of your suggestions. I also removed the servicemetadata section from the DefaultBehavior in config.
This fix only hides the original issue as I still have no idea why the mex binding was registered as 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.
Here's the corrected config
尝试在您的服务上启用跟踪,以检查测试/生产环境中出现故障的原因。要启用跟踪,请检查此链接
确保 MyWcfServiceHostFactory 没有任何与配置相关的代码(即通过 C# 代码构建配置)
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 (i.e. building configuration via c# code)