2016-07-25 79 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); 
相關問題