![](/img/trans.png)
[英]Why is my WCF wshttpbinding client doesn't work at another computer?
[英]How to work with WCF wsHttpBinding and SSL?
我需要開發WCF Hosted in a console app WebService
的WCF Hosted in a console app WebService
。 我通過使用SecurityMode.Message
使用Mutual Certificate (service and client)
方法來使其工作。 但是現在我需要將安全模式更改為SecurityMode.Transport
並使用帶SSL的wsHttpBinding
。 我編寫了此代碼來托管服務,但無法通過瀏覽器獲取wsdl,也無法在the console app
客戶端中執行某些webmethod。
static void Main()
{
var httpsUri = new Uri("https://localhost:8089/HelloServer");
var binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var host = new ServiceHost(typeof(WcfFederationServer.HelloWorld), httpsUri);
host.AddServiceEndpoint(typeof(WcfFederationServer.IHelloWorld), binding, "", httpsUri);
var mex = new ServiceMetadataBehavior();
mex.HttpsGetEnabled = true;
host.Description.Behaviors.Add(mex);
// Open the service.
host.Open();
Console.WriteLine("Listening on {0}...", httpsUri);
Console.ReadLine();
// Close the service.
host.Close();
}
服務已啟動,但是我在https://localhost:8089/HelloServer
上什么也收不到。 在提琴手上,通過瀏覽器的get請求向我顯示此消息:
fiddler.network.https> HTTPS handshake to localhost failed. System.IO.IOException
我在這里想念什么? 謝謝
編輯:
Console Application Client Code
static void Main()
{
try
{
var client = new HelloWorldHttps.HelloWorldClient();
client.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.LocalMachine,
StoreName.TrustedPeople,
X509FindType.FindBySubjectName,
"www.client.com");
Console.WriteLine(client.GetData());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
}
收到此錯誤:
Could not establish trust relationship for the SSL/TLS secure channel
關於服務,您需要按照以下說明將證書映射到特定端口
http://msdn.microsoft.com/en-us/library/ms733791(v=vs.110).aspx
對於客戶端,您需要通過放寬證書接受策略來跳過對證書屬性(如有效日期,域)的驗證。 最簡單的方法是接受任何證書
ServicePointManager.ServerCertificateValidationCallback = (a,b,c,d) => true
您可以根據文檔微調接受回調,以最適合您的需求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.