如何修复 WCF 中的“找不到与架构 http 匹配的基址”...
我正在尝试将 WCF 服务部署到托管在 IIS 中的服务器。 当然它可以在我的机器上运行:)
但是当我部署它时,我收到以下错误:
该集合已包含 地址为 http 方案。 有可以 每个方案至多有一个地址 这个集合。
谷歌搜索后,我发现我必须将 serviceHostingEnvironment 元素放入 web.config 文件中:
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://mywebsiteurl"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
但是一旦完成此操作,我会得到以下内容:
找不到基址 匹配端点的 http 方案 与绑定 BasicHttpBinding。 注册基地址方案是 [https]。
看起来它不知道基地址是什么,但是我如何指定它呢? 这是我的 web.config 文件的相关部分:
<system.serviceModel>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://mywebsiteurl"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="WcfPortalBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IWcfPortal"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
receiveTimeout="00:10:00" sendTimeout="00:10:00"
openTimeout="00:10:00" closeTimeout="00:10:00">
<readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647"
maxStringContentLength="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="WcfPortalBehavior" name="Csla.Server.Hosts.Silverlight.WcfPortal">
<endpoint address="" binding="basicHttpBinding" contract="Csla.Server.Hosts.Silverlight.IWcfPortal"
bindingConfiguration="BasicHttpBinding_IWcfPortal">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
任何人都可以了解正在发生的事情以及如何修复它吗?
I'm trying to deploy a WCF service to my server, hosted in IIS. Naturally it works on my machine :)
But when I deploy it, I get the following error:
This collection already contains an
address with scheme http. There can
be at most one address per scheme in
this collection.
Googling on this, I find that I have to put a serviceHostingEnvironment element into the web.config file:
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://mywebsiteurl"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
But once I have done this, I get the following:
Could not find a base address that
matches scheme http for the endpoint
with binding BasicHttpBinding.
Registered base address schemes are
[https].
It seems it doesn't know what the base address is, but how do I specify it? Here's the relevant section of my web.config file:
<system.serviceModel>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://mywebsiteurl"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="WcfPortalBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IWcfPortal"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
receiveTimeout="00:10:00" sendTimeout="00:10:00"
openTimeout="00:10:00" closeTimeout="00:10:00">
<readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647"
maxStringContentLength="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="WcfPortalBehavior" name="Csla.Server.Hosts.Silverlight.WcfPortal">
<endpoint address="" binding="basicHttpBinding" contract="Csla.Server.Hosts.Silverlight.IWcfPortal"
bindingConfiguration="BasicHttpBinding_IWcfPortal">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
Can anybody shed some light on what's going on and how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
尝试将安全模式从“传输”更改为“无”。
Try changing the security mode from "Transport" to "None".
我必须对站点/应用程序的 IIS 配置执行两件事。 我的问题与让 net.tcp 在 IIS 网站应用程序中工作有关:
首先:
其次:
I had to do two things to the IIS configuration of the site/application. My issue had to do with getting net.tcp working in an IIS Web Site App:
First:
Second:
您的 IIS 是否有可能配置为在连接到您的站点/应用程序时需要 SSL?
Any chance your IIS is configured to require SSL on connections to your site/application?
如果您想在 web.config 中使用 baseAddressPrefixFilters,则还必须设置 IIS (6)。 这帮助了我:
1/ 在 IIS 中找到您的站点。
2/ 属性/网站(选项卡)/IP 地址 -> 高级按钮
3/ 在您将在 web.config 中使用的同一端口上添加新的主机标头。
If you want to use baseAddressPrefixFilters in web.config, you must setup IIS (6) too. This helped me:
1/ In IIS find your site.
2/ Properties / Web site (tab) / IP address -> Advanced button
3/ Add new host header on the same port which you will use in web.config.
仅列表中的第一个基地址将被接管(来自 IIS)。
在 .NET4 之前,每个方案不能有多个基地址。
Only the first base address in the list will be taken over (coming from IIS).
You can't have multiple base addresses per scheme prior to .NET4.
解决方案是在 Web.Config 文件中定义自定义绑定,并将安全模式设置为“传输”。 然后,您只需在端点定义中使用 bindingConfiguration 属性来指向您的自定义绑定。
请参阅此处: Scott 的博客:WCF HTTPS 所需的绑定
The solution is to define a custom binding inside your Web.Config file and set the security mode to "Transport". Then you just need to use the bindingConfiguration property inside your endpoint definition to point to your custom binding.
See here: Scott's Blog: WCF Bindings Needed For HTTPS
如果托管在IIS中,则无需指定基地址,它将是虚拟目录的地址。
If it is hosted in IIS, there is no need to specify a base address, it will be the address of the virtual directory.
应该有一种方法可以通过外部配置部分和额外的部署步骤轻松解决此问题,该步骤将部署特定的外部 .config 文件放入已知位置。 我们通常使用此解决方案来处理不同部署环境(暂存、QA、生产等)的不同服务器配置,如果没有特殊副本发生,我们的“开发盒”将成为默认值。
There should be a way to solve this pretty easily with external config sections and an extra deployment step that drops a deployment specific external .config file into a known location. We typically use this solution to handle the different server configurations for our different deployment environments (Staging, QA, production, etc) with our "dev box" being the default if no special copy occurs.
确认我的修复:
在您的 web.config 文件中,您应该将其配置为如下所示:
然后,构建一个如下所示的文件夹结构:
基本 serviceHosting.config 应如下所示:
而 /Deploy 中的那个如下所示:
除此之外,您还需要添加手动或自动部署步骤,以将 /Deploy 中的文件复制到 /Configurations 中的文件之上。 这对于服务地址和连接字符串非常有效,并且可以节省执行其他解决方法的精力。
如果您不喜欢这种方法(它可以很好地扩展到服务器场,但在单台计算机上较弱),您可以考虑在主机计算机上的服务部署的基础上添加一个 web.config 文件,并将 serviceHostingEnvironment 节点放在那里。 它应该为你级联。
Confirmed my fix:
In your web.config file you should configure it to look as such:
Then, build a folder structure that looks like this:
The base serviceHosting.config should look like this:
while the one in /Deploy looks like this:
Beyond this, you need to add a manual or automated deployment step to copy the file from /Deploy overtop the one in /Configurations. This works incredibly well for service address and connection strings, and saves effort doing other workarounds.
If you don't like this approach (which scales well to farms, but is weaker on single machine), you might consider adding a web.config file a level up from the service deployment on the host's machine and put the serviceHostingEnvironment node there. It should cascade for you.