简体   繁体   English

根据system.ServiceModel转换C#绑定对象

[英]Convert c# binding object based on the system.ServiceModel

Can anybody help me create a binding object in C# based on the configuration provided below. 谁能帮助我根据下面提供的配置在C#中创建绑定对象。 This is copied from app.config of the project where my wcf service is referenced. 这是从引用我的wcf服务的项目的app.config中复制的。

<system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="BindingName">
          <security defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport"
            requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
            <localClientSettings detectReplays="false" />
            <localServiceSettings detectReplays="false" />
          </security>
          <textMessageEncoding messageVersion="Soap12" />
          <httpsTransport />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="https://example.com/test.svc"
        binding="customBinding" bindingConfiguration="BindingName"
        contract="Service.IService" name="BindingName" />
    </client>
  </system.serviceModel>

Try this 尝试这个

   var config = new BindingElementCollection();

        TransportSecurityBindingElement transportSecurityBindingElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();

        transportSecurityBindingElement.IncludeTimestamp = true;
        transportSecurityBindingElement.MessageSecurityVersion =
            MessageSecurityVersion
                .WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
        transportSecurityBindingElement.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Default;
        transportSecurityBindingElement.LocalClientSettings.DetectReplays = false;
        transportSecurityBindingElement.LocalServiceSettings.DetectReplays = false;
        transportSecurityBindingElement.SetKeyDerivation(true);

        config.Add(transportSecurityBindingElement);
        config.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap12, Encoding.UTF8));
        config.Add(new HttpsTransportBindingElement());

        return new CustomBinding(config);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.ServiceModel引用 - System.ServiceModel References System.ServiceModel消失 - System.ServiceModel disappear System.ServiceModel缺失 - System.ServiceModel missing system.serviceModel / bindings / wsHttpBinding处的绑定没有配置的绑定 - The binding at system.serviceModel/bindings/wsHttpBinding does not have a configured binding system.serviceModel / bindings / wsHttpBinding处的绑定没有……错误 - The binding at system.serviceModel/bindings/wsHttpBinding does not have… error 找不到配置绑定扩展“system.serviceModel/bindings/basicHttpsBinding” - Configuration binding extension 'system.serviceModel/bindings/basicHttpsBinding' could not be found 找不到配置绑定扩展名&#39;system.serviceModel / bindings / pollingDuplexHttpBinding&#39; - Configuration binding extension 'system.serviceModel/bindings/pollingDuplexHttpBinding' could not be found 修复 LINQPad 中 System.ServiceModel 的“他们键入 &#39;X&#39; 存在于 &#39;Y&#39; 和 &#39;Z&#39; 中”的 C# 错误 - Fixing "They type 'X' exists in both 'Y' and 'Z'" C# error for System.ServiceModel in LINQPad 在运行时在APP.Config C#中添加节点system.serviceModel - Add node system.serviceModel in APP.Config C# in runtime Windows Phone 8中的System.ServiceModel发生了什么? - What happened with System.ServiceModel in Windows Phone 8?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM