【问题标题】:WCF service returns 404 over https but not httpWCF 服务通过 https 而不是 http 返回 404
【发布时间】:2010-10-06 21:14:24
【问题描述】:

我正在将现有服务从 HTTP (Dev/UAT) 迁移到 HTTPS (Production),但我遇到了配置问题。这是我的 web.config 的 system.serviceModel 部分:

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
    <services>
      <service name="MyService">
        <endpoint name="MyEndpoint" address="" binding="wsHttpBinding"
            bindingConfiguration="secureBinding" contract="IMyService" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="secureBinding">
          <security mode="Transport"></security>
        </binding>
      </wsHttpBinding>
    </bindings>
</system.serviceModel>

我用basicHttpBindingwsHttpBinding 都试过了,结果是一样的:

  • 我可以使用 http://server.domain.com/MyService.svc 从我的 SOAP 客户端调用服务
  • 我可以使用https://server.domain.com/MyService.svc 从浏览器中访问该服务
  • 我无法使用 https://server.domain.com/MyService.svc 从我的 SOAP 客户端调用服务 - 使用 404: not found 时调用总是出错。

我的 https 站点已使用公司域上的 CA 颁发的证书进行了认证,并且我已验证我已在我发出呼叫的系统上的 Trusted Root Certification Authorities 中安装了该 CA 的证书。

相关客户端代码:

Service service = new Service();
service.Url = "http://server.domain.com/MyService.svc";
//service.Url = "https://server.domain.com/MyService.svc";
service.WebMethodCall();

编辑

以下是 WSDL 的请求部分:

<wsdl:types/>
<wsdl:portType name="IMyService"/>
<wsdl:binding name="BasicHttpBinding_IMyService" type="tns:IMyService">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
</wsdl:binding>
<wsdl:service name="MyService">
    <wsdl:port name="BasicHttpBinding_IMyService" 
        binding="tns:BasicHttpBinding_IMyService">
        <soap:address location="http://server.domain.com/MyService.svc"/>
    </wsdl:port>
</wsdl:service>

编辑

更多信息:

当我将 serviceMetadata 元素更改为具有 httpGetEnabled="false"httpsGetEnabled="true" 时,.svc 页面会显示以下链接:

https://boxname.domain.com/MyService.svc?wsdl

而不是预期

https://server.domain.com/MyService.svc?wsdl

【问题讨论】:

  • 如果您在生产环境中为您的服务生成 WSDL,它是否包含 HTTPS 端口?
  • 我将在编辑中添加关于 WSDL 的注释
  • 这是预期的,因为您的 serviceMetadata 仅启用 httpGet 而不是 httpsGet。此外,您无法获得服务参考,因为您没有公开 mex 端点。当您通过 HTTP 访问 WSDL 时,重要的是它的内容——尤其是描述服务和端口的最后部分。

标签: wcf soap https


【解决方案1】:

检查 web.config 中的服务元素名称是否与实现合同的类的完全限定名称匹配。

<services>
  <service name="MyNamespace.MyService">
    <endpoint name="MyEndpoint" address="" binding="wsHttpBinding" ...

【讨论】:

  • 这原来是我遇到的问题 - 在我更新服务名称值后,https 端点开始出现在我的 WSDL 中。我必须在 IIS 中为站点设置主机标头以获取 正确 端点,但它们确实出现了。
【解决方案2】:

在您的 WSDL 中,您会看到您的服务并未在 HTTPS 上公开端口,而仅在 HTTP 上公开。此外,您还可以看到您的服务使用 BasicHttpBinding(请参阅端口名称和绑定名称)。这意味着根本不使用您的服务配置。检查服务元素中的名称是否与 .svc 标记中的名称相同。它必须定义包括命名空间。

【讨论】:

  • 如果我更改了 .svc 文件中 ServiceHost 指令的 Service 属性中的名称,或者如果我更改了 Web 中 service 元素的 name 属性。配置,我立即得到一个黄色屏幕,说找不到命名服务。我的endpoint 声明有问题吗?
  • 事实上,更改endpointany 部分会导致其中断。显然是在解析 web.config 文件;真的不用吗?
【解决方案3】:

HTTP 和 HTTPS 由不同的虚拟主机提供服务。你确定你的服务都正确安装了吗?

【讨论】:

  • 什么意思?我有一个网站,上面有两个绑定:http://server.domain.comhttps://server.domain.com
  • 啊,好的。这很奇怪。运行 Fiddler 或其他东西来捕获流量会产生什么有趣的东西吗? (服务器的访问日志显示什么?)
  • Fiddler 显示请求已通过,但由于加密,它无法向我显示任何有趣的内容。在哪里可以查看 IIS 的流量日志?
【解决方案4】:

感谢 Johann Blais 的回答,我发现您需要包含定义服务合同的类的完全限定名称。

例如,如果您的服务是

namespace MyCompany.WcfService
{

    [ServiceContract(Namespace="http://xsd.mycompany.com/mcy/1_0_0")]
    public interface IService
    {
        [OperationContract(IsOneWay = false)]
        void DoStuff()
    }

    public class Service : IService
    {
        void DoStuff()
        {
        }
    }
}

您的 web.config 中相应的服务定义将是

<system.serviceModel>
    <services>
        <service name="MyCompany.WcfService.IService">
            <endpoint address="" binding="basicHttpBinding" contract="MyCompany.WcfService.IService" />
        </service>
    </services>
    ...
</system.serviceModel>

【讨论】:

    猜你喜欢
    • 2019-11-21
    • 2014-08-06
    • 2020-04-19
    • 1970-01-01
    • 2012-05-27
    • 2013-11-02
    • 2012-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多