WCF - how to create programatically custom binding with binary encoding over HTTP(S)

后端 未结 3 860
有刺的猬
有刺的猬 2021-02-09 19:53

I\'d like to convert my current HTTP/HTTPS WCF binding settings to use binary message encoding and I need to do it in code - not in XML configuration. AFAIK it\'s necessary to

3条回答
  •  不要未来只要你来
    2021-02-09 20:59

    Try SecurityBindingElement.CreateUserNameOverTransportBindingElement() instead:

    var custBinding = new CustomBinding();
    custBinding.Elements.Add(new BinaryMessageEncodingBindingElement());
    //Transport Security (Not Required)
    if (isHttps)
    {
      custBinding.Elements.Add(SecurityBindingElement.CreateUserNameOverTransportBindingElement());
    }
    //Transport (Required)
    custBinding.Elements.Add(isHttps ?
       new HttpsTransportBindingElement() :
       new HttpTransportBindingElement());
    

提交回复
热议问题