3

我查看了所有其他解决方案,但没有一个有效。我正在使用 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)未找到。”

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

4

1 回答 1

2

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

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

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

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

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

        </service>
    </services>
    <behaviors> 
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
于 2012-07-12T23:00:50.730 回答