具有 WsHttpBinding 的客户端应用程序获得 "no endpoint listening at..."

Client App with WsHttpBinding gets "no endpoint listening at..."

我有一个客户端应用程序,它与我们在服务器上托管的 Web 服务对话(我们将其称为 hostServer)。我的客户端应用程序可以使用 basicHttpBinding 正常构建和连接。但是,出于安全原因,我试图实现 wsHttpBinding

上周午餐前我可以发誓它正在使用硬编码证书。吃完午饭回来,检查了我的代码,现在它不会 运行。我不断收到 "There was no endpoint listening at https://hostServer:1234/Service.svc/MyServiceName that could accept the message. This is often caused by an incorrect address or SOAP action."。我已经尝试 re-checking 我的设置,回顾我的步骤,但似乎无法回到我之前的功能状态。

我正在使用地址为 "https ://hostServer:1234/Service.svc?singleWsdl" 的 ServiceReference。我可以毫无问题地导航到 "https ://hostServer:1234/Service.svc" 并查看 Wsdl。

我的客户端代码是

WSHttpBinding wsBinding = new WSHttpBinding(SecurityMode.Transport);
wsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

Client = new MyServiceName(wsBinding, new EndpointAddress(endpoint));

Client.ClientCredentials.ClientCertificate.SetCertificate(
  StoreLocation.CurrentUser,
  StoreName.My,
  X509FindType.FindBySubjectName,
  "localCertName");

 Client.ChangePassword("test_user", "pt", "a1");

我的值端点 = https://hostServer:1234/Service.svc/MyServiceName

我的 IIS 站点设置了 Http 和 Https 绑定(具有正确的 IP 和端口 ID)

我真的需要在起飞前让这段代码正常工作(我的妻子随时都将迎来我们的第二个 child)。我现在已经调试它 2 天了,除了我花时间让它保持原样。请帮忙。

所以我终于能够让它再次工作了。列出下面执行的步骤,希望对其他人有所帮助。

在 IIS 服务器(IIS 管理器)上

已修改 "Site Bindings" 以包含 HTTP 和 HTTPS(w/different 端口号)

将 SSL 设置设为 "Require SSL" 和 "Accept"

在 IIS 服务器上 (Web.Config):

已添加

<bindings> 
  <wsHttpBinding> 
    <binding name="wsHttpEndpointBinding"> 
      <security mode="Transport"> 
        <transport clientCredentialType ="Certificate"/> 
      </security> 
    </binding> 
  </wsHttpBinding> 
</bindings>

到 "System.ServiceModel" 标签。

此外,已将 'bindingConfiguration="wsHttpEndpointBinding"' 添加到我的端点。

在代码中

更新端点地址以使用在 IIS 服务器上生成的地址。

使用以下代码创建端点

 WSHttpBinding wsBinding = new WSHttpBinding(SecurityMode.Transport); 
    wsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; 
    Client = new ServiceClient(wsBinding, new EndpointAddress(endpoint)); 
    Client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMac‌​hine, StoreName.My, X509FindType.FindByIssuerName, certName);