开发者

Transport security between Metro service and WCF client

UPDATED

I have a Metro 2.1.1 WebService secured with the mechanism Transport Security (SSL). I want to access this service with a .NET 3.5+ WCF client. I found this link which solves开发者_运维问答 the same problem problem, however I was still unable to make a working client. I think I'm mixing up stuff in the client config.


The WCF team has released a set of interoperability bindings at this link. This blog post provides details on how to use them. One of the supported bindings is specifically for Metro based service. Haven't tried to set this binding up but it seems this scenario is covered.


Client Code:

//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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜