How can I programmatically create this custom binding?

后端 未结 3 1022
情深已故
情深已故 2020-12-23 15:21

We\'ve got to access a web service that uses soap11... no problem I\'ll just set the binding as:

BasicHttpBinding wsBinding = new BasicHttpBinding(BasicHttpS         


        
3条回答
  •  萌比男神i
    2020-12-23 15:28

    Solved it!

    Here's the winning code for those who are in a similar predicament.

    Uri epUri = new Uri(_serviceUri);
    CustomBinding binding = new CustomBinding();
    SecurityBindingElement sbe = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
    sbe.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11;        
    sbe.SecurityHeaderLayout = SecurityHeaderLayout.Strict;
    sbe.IncludeTimestamp = false;
    sbe.SetKeyDerivation(true);
    sbe.KeyEntropyMode = System.ServiceModel.Security.SecurityKeyEntropyMode.ServerEntropy;
    binding.Elements.Add(sbe);
    binding.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, System.Text.Encoding.UTF8));
    binding.Elements.Add(new HttpsTransportBindingElement());
    EndpointAddress endPoint = new EndpointAddress(epUri);
    

提交回复
热议问题