WCF 端点无法在 IIS(Express) 上运行

发布于 2024-11-25 03:39:30 字数 1619 浏览 10 评论 0原文

我正在尝试让端点在 IIS (Express) 上工作。 当使用 IIS Express 在 VS 中调试项目并在浏览器中打开端点地址时,我只收到正常的 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" %>

I'm trying to get an endpoint working on IIS (Express).
When debugging the project in VS with IIS Express and opening the endpoint address in my browser, I just get a normal 404 error.

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

When I place a .svc-Datei with the following contents into the website root, its working fine:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

浪菊怪哟 2024-12-02 03:39:30

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

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

现在,您可以使用 serviceActivations 或者如果您使用 ASpNetCompaibility 可以使用 ServiceRoute 作为 这篇文章显示

When using IIS hosting you should not provide your own base address. The base address for the service is given by the location of a .svc file. The endpoint address is then relative to the .svc file

The .svc file is used by IIS to map the request to WCF (rather than, say, ASP.NET).

Now you can have a virtual .svc file rather than a physical one using serviceActivations or if you use ASpNetCompaibility to can remove the .svc part altogether using a ServiceRoute as this article shows

却一份温柔 2024-12-02 03:39:30

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

I think you've answered your own question. When hosting over HTTP you need a .svc file so that the web server can instantiate the service. Other bindings such as net.tcp or net.msmq do not have this requirement.

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