如何修复 WCF 中的“找不到与架构 http 匹配的基址”...

发布于 2024-07-19 19:45:21 字数 2257 浏览 11 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

南街九尾狐 2024-07-26 19:45:21

尝试将安全模式从“传输”更改为“无”。

      <!-- Transport security mode requires IIS to have a
           certificate configured for SSL. See readme for
           more information on how to set this up. -->
      <security mode="None">

Try changing the security mode from "Transport" to "None".

      <!-- Transport security mode requires IIS to have a
           certificate configured for SSL. See readme for
           more information on how to set this up. -->
      <security mode="None">
挽梦忆笙歌 2024-07-26 19:45:21

我必须对站点/应用程序的 IIS 配置执行两件事。 我的问题与让 net.tcp 在 IIS 网站应用程序中工作有关:

首先:

  1. 右键单击 IIS 应用程序名称。
  2. 管理网站
  3. 高级设置
  4. 将启用的协议设置为“http,net.tcp”

其次:

  1. 在管理器右侧的“操作”菜单下,单击“绑定...”
  2. 单击“添加” 将
  3. 类型更改为“net.tcp”
  4. 将绑定信息设置为{开放端口号}:*
  5. 确定

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:

  1. Right click on the IIS App name.
  2. Manage Web Site
  3. Advanced Settings
  4. Set Enabled protocols to be "http,net.tcp"

Second:

  1. Under the Actions menu on the right side of the Manager, click Bindings...
  2. Click Add
  3. Change type to "net.tcp"
  4. Set binding information to {open port number}:*
  5. OK
┊风居住的梦幻卍 2024-07-26 19:45:21

您的 IIS 是否有可能配置为在连接到您的站点/应用程序时需要 SSL?

Any chance your IIS is configured to require SSL on connections to your site/application?

谎言月老 2024-07-26 19:45:21

如果您想在 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.

随遇而安 2024-07-26 19:45:21

仅列表中的第一个基地址将被接管(来自 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.

不羁少年 2024-07-26 19:45:21

解决方案是在 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

脱离于你 2024-07-26 19:45:21

如果托管在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.

内心荒芜 2024-07-26 19:45:21

应该有一种方法可以通过外部配置部分和额外的部署步骤轻松解决此问题,该步骤将部署特定的外部 .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.

仅冇旳回忆 2024-07-26 19:45:21

确认我的修复:

在您的 web.config 文件中,您应该将其配置为如下所示:

<system.serviceModel >
    <serviceHostingEnvironment configSource=".\Configurations\ServiceHosting.config" />
    ...

然后,构建一个如下所示的文件夹结构:

/web.config
/Configurations/ServiceHosting.config
/Configurations/Deploy/ServiceHosting.config

基本 serviceHosting.config 应如下所示:

<?xml version="1.0"?>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
    <baseAddressPrefixFilters>
    </baseAddressPrefixFilters>
</serviceHostingEnvironment>

而 /Deploy 中的那个如下所示:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
    <baseAddressPrefixFilters>
        <add prefix="http://myappname.web707.discountasp.net"/>
    </baseAddressPrefixFilters>
</serviceHostingEnvironment>

除此之外,您还需要添加手动或自动部署步骤,以将 /Deploy 中的文件复制到 /Configurations 中的文件之上。 这对于服务地址和连接字符串非常有效,并且可以节省执行其他解决方法的精力。

如果您不喜欢这种方法(它可以很好地扩展到服务器场,但在单台计算机上较弱),您可以考虑在主机计算机上的服务部署的基础上添加一个 web.config 文件,并将 serviceHostingEnvironment 节点放在那里。 它应该为你级联。

Confirmed my fix:

In your web.config file you should configure it to look as such:

<system.serviceModel >
    <serviceHostingEnvironment configSource=".\Configurations\ServiceHosting.config" />
    ...

Then, build a folder structure that looks like this:

/web.config
/Configurations/ServiceHosting.config
/Configurations/Deploy/ServiceHosting.config

The base serviceHosting.config should look like this:

<?xml version="1.0"?>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
    <baseAddressPrefixFilters>
    </baseAddressPrefixFilters>
</serviceHostingEnvironment>

while the one in /Deploy looks like this:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
    <baseAddressPrefixFilters>
        <add prefix="http://myappname.web707.discountasp.net"/>
    </baseAddressPrefixFilters>
</serviceHostingEnvironment>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文