【问题标题】:WCF Won't Work Over HTTPSWCF 不能通过 HTTPS 工作
【发布时间】:2012-07-12 22:24:09
【问题描述】:

我查看了所有其他解决方案,但没有一个有效。我正在使用 IIS 托管 WCF 服务。以下是我的 web.config(我添加 WCF 服务时的默认配置):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
    </compilation>
    <customErrors mode="Off" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
</configuration>

一切都很好,我可以在浏览器中使用 http://www.domain.com/path/service.svchttps://www.domain.com/path/service.svc 访问我的 wcf 服务 - 现在我在 Windows 控制台应用程序中添加对 https://www.domain.com/path/service.svc 的 Web 引用,以下内容位于我的 app.config 中:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="defaultBasicHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://www.domain.com/path/service.svc" binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding" contract="DomainExt.IExt" name="BasicHttpBinding_IExt" />
    </client>
  </system.serviceModel>
</configuration>

以下代码是我用来测试服务的代码:

public static String DoPing()
{
     ExtClient client = new ExtClient("BasicHttpBinding_IExt", "https://www.domain.com/path/service.svc");
     return client.DoPing();
}

运行此程序后,我得到以下异常:

https://www.domain.com/path/service.svc 上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关详细信息,请参阅 InnerException(如果存在)。

内部异常状态:

“远程服务器返回错误:(404) Not Found。”

此服务在 http 上运行良好,但在 https 上失败。我怎样才能解决这个问题?请注意,我使用 Windows 控制台而不是通过 ASP.NET 访问此服务; ASP.NET 仅托管 WCF 服务。

【问题讨论】:

  • 您在 IIS 中的绑定设置是什么?如果您运行 netmon,您会看到尝试的 SSL 握手吗?
  • 我有 3 个绑定。 “http domain.com 80 *” - “http (blank) 80 10.0.3.3” - “http www.domain.com 80 *” - “https (blank) 443 10.0.3.3” 我不熟悉netmon。
  • 您是否在某处的代码中为您的主机创建绑定和服务端点?如果是这样,你也可以发布吗?
  • 我不是。我在代码中唯一要做的是ExtClient client = new ExtClient("BasicHttpBinding_IExt", ServiceURL);,其中 ExtClient 是对服务的引用,而 ServiceURL 是我对从注册表中获取的 URL 进行硬编码的地方。

标签: c# wcf


【解决方案1】:

尝试设置 httpsGetEnabled="true" 而不是 httpGetEnabled

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpsGetEnabled="true" />

编辑:如果您使用 SSL,我也很好奇您为什么选择 BasicHttpBinding。为什么不使用 WsHttpBinding?

EDIT2:您的主机配置文件中是否缺少&lt;services&gt; 节点?我不认为你可以创建一个没有客户的客户。您可以右键单击您的 app.config 文件并在那里进行配置...像这样:

    <services>
        <service behaviorConfiguration="MyServiceBehavior" name="MyService">
            <endpoint address="" binding="defaultBasicHttpBinding" bindingConfiguration="basicBinding" contract="IMyService" />

        </service>
    </services>
    <behaviors> 
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">

【讨论】:

  • 我仍然收到同样的错误,“在https://www.domain.com/path/service.svc 没有可以接受消息的端点监听。这通常是由不正确的地址或 SOAP 操作引起的。请参阅 InnerException,如果存在, 更多细节。”我实际上从不选择 BasicHttpBinding 而是自动创建的。我的知识是 WCF 的基础知识,因为我还在学习它。
  • 你能发布你的整个主机配置文件吗?
  • 主机配置文件是什么意思?
  • 这是你的整个 web.config 文件吗?
  • 是的。我刚开始创建这个网站,因此规模很小。
猜你喜欢
  • 2011-05-22
  • 1970-01-01
  • 2015-06-22
  • 1970-01-01
  • 1970-01-01
  • 2014-12-20
  • 1970-01-01
  • 2019-11-21
  • 1970-01-01
相关资源
最近更新 更多