簡體   English   中英

Metro 服務與 WCF 客戶端之間的傳輸安全性

[英]Transport security between Metro service and WCF client

更新

我有一個使用Transport Security (SSL)機制保護的 Metro 2.1.1 WebService。 我想使用 .NET 3.5+ WCF 客戶端訪問此服務。 我發現這個鏈接解決了同樣的問題,但是我仍然無法創建一個工作客戶端。 我想我在客戶端配置中混合了一些東西。

WCF 團隊在 此鏈接上發布了一組互操作性綁定。 博客文章提供了有關如何使用它們的詳細信息。 受支持的綁定之一專門用於基於 Metro 的服務。 尚未嘗試設置此綁定,但似乎已涵蓋此場景。

客戶代碼

//IMPORTANT - THIS LINE IS ONLY FOR TESTING PURPOSES!
//This code is for accepting self-signed server certificate
ServicePointManager.ServerCertificateValidationCallback += (sender_ws, cert, chain, sslPolicyErrors) => true;

//instantiate transport binding element, leave the defaults
HttpsTransportBindingElement transport = new HttpsTransportBindingElement();

//instantiate message encoding element, where message version must be Soap11WSAddressing10 to match metro web service requirement.
TextMessageEncodingBindingElement text = new TextMessageEncodingBindingElement();
text.MessageVersion = MessageVersion.Soap11WSAddressing10;

//instantiate transport security binding element, with all the suggested values in app.config
TransportSecurityBindingElement b_element = new TransportSecurityBindingElement();
b_element.DefaultAlgorithmSuite = new Basic128SecurityAlgorithmSuite();
b_element.IncludeTimestamp = true;
b_element.KeyEntropyMode = SecurityKeyEntropyMode.CombinedEntropy;
b_element.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11;
b_element.SecurityHeaderLayout = SecurityHeaderLayout.Lax;

//instantiate the custom binding and add the elements created above
CustomBinding customBinding = new CustomBinding();
customBinding.Name = "myOwnPersonalCustomBinding";
customBinding.Elements.Add(b_element);
customBinding.Elements.Add(text);
customBinding.Elements.Add(transport);

//instantiate the client

Uri uri = new Uri("https://localhost:8181/test/hello");
HelloWebServiceClient  wsClient = new HelloWebServiceClient (customBinding, new EndpointAddress(uri));
//Call
richTextBox1.Text = wsClient.hello(textBox1.Text);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM