2016-07-25 83 views
0

我有一个客户端应用程序,它与我们在服务器上托管的Web服务进行通信(我们将其称为hostServer)。我的客户端应用程序可以使用basicHttpBinding进行构建和连接。不过,出于安全原因,我试图暗示wsHttpBindingWsHttpBinding的客户端应用程序得到“没有端点在... ...监听”

上午在午餐前我可以发誓它正在使用硬编码证书。从午餐回来,检查我的代码,现在它不会运行。我一直在收到“没有端点在https://hostServer:1234/Service.svc/MyServiceName上倾听,可能会接受该消息,这通常是由不正确的地址或SOAP操作引起的。”我尝试重新检查我的设置,回溯我的步骤,但似乎无法恢复到我正在运行的状态。

我正在使用服务引用的地址为“https:// hostServer: 1234/Service.svc?singleWsdl”。我可以毫无问题地导航到“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)

我真的需要在起飞之前让这段代码工作(我的妻子将在任何一天与我们的第二个孩子到期)。我一直在努力调试这个为期两天的时间,除此之外我还需要现在的时间。请帮忙。

回答

0

所以我终于能够再次得到这个工作。列出下面执行的步骤,希望它可以帮助其他人。

在IIS服务器(IIS管理器)

修改 “网站绑定” 包括HTTP & HTTPS(W /不同的端口号)

设置SSL设置为 “要求SSL” 和“接受“

在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); 
相关问题