我查看了所有其他解决方案,但没有一个有效。我正在使用 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.svc和https://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 服务。