【问题标题】:.NET 4 WCF SOAP Service Http POST returns 404 NOT Found.NET 4 WCF SOAP 服务 Http POST 返回 404 NOT Found
【发布时间】:2011-07-10 16:39:32
【问题描述】:

我有 WCF 托管的 SOAP 服务,在发出 HTTP GET 请求时,我可以从浏览器和我的 SOAP 客户端正常访问该服务,但是,在执行任何 HTTP POST 请求时,响应是 404 Not Found。

我的 Web.config 看起来像:

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
    <bindings>
        <wsHttpBinding>
            <binding>
                <security mode="Transport">
                    <transport clientCredentialType="Certificate" />
                </security>
                <readerQuotas maxDepth="15" maxStringContentLength="524288" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>
        </wsHttpBinding>
        <basicHttpBinding>
            <binding>
                <readerQuotas maxDepth="15" maxStringContentLength="524288" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>
        </basicHttpBinding>
    </bindings>
</system.serviceModel>

我的服务在标记中使用 .svc 文件定义为:

<%@ ServiceHost Language="C#" Debug="true" Service="Boca.WebServices.Billing.QBService" CodeBehind="QBService.svc.cs" %>

同样,我可以使用浏览器和 SOAP 客户端访问我的服务,如下所示,使用 HTTP GET 但不能使用 HTTP POST:

我做错了什么?我是否应该不使用 .svc 标记而只在 Web.config 中定义我的服务?

更新:

当我在 VS 2010 中使用 IIS Express 在 localhost:8181 端口上“开始调试”我的 WCF 项目时,该服务的 HTTP POSTS 工作。只有当服务通过 IIS 托管时,服务的 HTTP POST 才会被拒绝或找不到。

【问题讨论】:

    标签: wcf soap wcf-binding


    【解决方案1】:

    我已经解决了这个问题。毕竟,这不是 IIS 问题,而是我没有使用 &lt;security&gt; 节点配置 &lt;basicHttpBinding&gt; 的问题。我没有彻底了解绑定及其工作原理,所以我认为在&lt;basicHttpBinding&gt; 旁边添加&lt;wsHttpBinding&gt; 会增加对WCF 的SSL 支持。

    这样做并使用&lt;security&gt; 节点配置默认&lt;wsHttpBinding&gt; 绝对允许我安全地获取SOAP 元数据,即使在内部它仍在使用&lt;basicHttpBinding&gt;,但不支持POST。

    我更新了我的配置,将 transport clientCredentialType 设置为 None 并解决了问题:

    <bindings>
        <basicHttpBinding>
            <binding name="QBService_BasicHttpBinding">
                <security mode="Transport">
                    <transport clientCredentialType="None" />
                </security>
                <readerQuotas maxDepth="15" maxStringContentLength="524288" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>
        </basicHttpBinding>
    </bindings>
    

    【讨论】:

      【解决方案2】:

      假设您使用的是 .NET 4,您的服务将使用 basicHttpBinding 监听一个或多个端点 - 如果您在使用 HTTP 时未指定端点,则这是默认设置

      如果您只有一个服务合同,那么您的服务将在以 .svc 结尾的地址处侦听 HTTP POST。如果您有多个服务合同,则它将每个合同托管在&lt;path to .svc&gt;/&lt;serviceContractname&gt;之类的地址

      该服务需要一个 SOAP 请求,因此您需要 POST 一个与 SOAP 1.1 匹配的 XML 文档(basicHttpBinding 默认为此)。实现这一点的最简单方法是在客户端项目中使用 Add Service Reference 构建代理并通过生成的代理类进行调用 - WCF 管道将生成适当的消息并将其发布到服务

      【讨论】:

      • 问题是执行 HTTP POST 会导致 404,而执行 HTTP GET 则有效。此外,我注意到,如果我在 VS 2010 中使用 IIS Express 调试我的 VS 2010 WCF 项目,则服务的 HTTP POST 工作正常。我似乎只有在通过 IIS 托管时才会看到这种行为。
      • 我认为将其视为“检索元数据有效但发出服务请求失败并出现 404”会更有用。我假设您正在使用 Add Service Reference 或浏览器进行 GET,而 POST 使用认为生成的代理的请求 - 这是正确的吗?
      • 另外,你的服务实现了多少服务契约?
      • QuickBooks Web 连接器 SDK 通过客户端参考进行 POST。我的服务实现了 1 个服务合同,其中包含大约 10 个操作。
      • 在 WSDL 中服务的地址是什么?您是否在其中获得了客户端无法路由的内容?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多