【问题标题】:WCF Endpoint not working on IIS(Express)WCF 端点在 IIS(Express)上不起作用
【发布时间】:2011-10-08 08:37:06
【问题描述】:

我正在尝试让一个端点在 IIS (Express) 上工作。 在 VS 中使用 IIS Express 调试项目并在我的浏览器中打开端点地址时,我只是得到一个正常的 404 错误。

我的 web.config:

<?xml version="1.0"?>
<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
      <behaviors>
        <serviceBehaviors>
          <behavior>
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug httpHelpPageEnabled="false" includeExceptionDetailInFaults="true"/>
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <services>
        <service name="A.B.C">
          <host>
            <baseAddresses>
              <add baseAddress="http://localhost:15000"/>
            </baseAddresses>
          </host>
          <endpoint address="Test" binding="basicHttpBinding" contract="A.B.IC" bindingConfiguration="A.B.C">

          </endpoint>
        </service>
      </services>
      <bindings>
        <basicHttpBinding>
          <binding name="A.B.C"
                   maxBufferPoolSize="20971520"
                   maxBufferSize="2097152"
                   maxReceivedMessageSize="2097152">
          </binding>
        </basicHttpBinding>
      </bindings>
    </system.serviceModel>
</configuration>

当我将具有以下内容的 .svc-Datei 放入网站根目录时,它工作正常:

<%@ ServiceHost Service="A.B.C" CodeBehind="Services/C.svc.cs" %>

【问题讨论】:

    标签: wcf iis http-status-code-404 iis-express endpoint


    【解决方案1】:

    我想你已经回答了你自己的问题。通过 HTTP 托管时,您需要一个 .svc 文件,以便 Web 服务器可以实例化该服务。其他绑定如 net.tcp 或 net.msmq 没有这个要求。

    【讨论】:

    • 这不适用于 WAS 托管 - 默认情况下,WAS 托管需要 .svc 文件,因为任何绑定自托管不需要
    【解决方案2】:

    使用 IIS 托管时,您不应提供自己的基地址。服务的基地址由 .svc 文件的位置给出。然后端点地址是相对于 .svc 文件的

    IIS 使用 .svc 文件将请求映射到 WCF(而不是 ASP.NET)。

    现在您可以使用serviceActivations 拥有一个虚拟 .svc 文件而不是物理文件,或者如果您使用 ASpNetCompaibility 可以使用 ServiceRoute 完全删除 .svc 部分,如this 文章所示

    【讨论】:

    • 因此添加 &lt;serviceHostingEnvironment&gt; &lt;serviceActivations&gt; &lt;add relativeAddress="Test123.svc" service="A.B.C"/&gt; &lt;/serviceActivations&gt; &lt;/serviceHostingEnvironment&gt; ,删除 &lt;host&gt;&lt;/host&gt; 部分并将端点地址更改为 /Test 应该在 /Test123.svc/ 处打开一个端点测试?
    • 是的,它应该(尽管您不需要地址开头的 /)并且通过查看您的配置,您应该能够从 /test123.svc?wsdl 获取 wsdl
    • 哇,确实如此。从&lt;behavior&gt; 部分中删除&lt;serviceDebug httpHelpPageEnabled="false"/&gt; 之后。谢谢!是否有可能更改 /Test123.svcmaxBufferSize?我只添加 /Test123.svc/Test-Endpoint 以便能够添加 bindingConfiguration
    • 只要您在 .NET 4 上,您就可以更改绑定配置而无需显式声明端点 - 只需使用您的设置为 basicHttpBinding 创建一个未命名的绑定。任何端点(包括如果您未指定任何端点设置的默认端点)将获取这些值,而不必通过 bindingConfiguration 引用它们。如果您不在 .NET 4 上,则必须照常做
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-10
    • 2015-05-05
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 2013-03-13
    相关资源
    最近更新 更多