如何在webconfig中添加bindingExtensions?

时间:2018-06-30 14:52:29

标签: web-services wcf custom-binding

我只是想添加bindingExtensions,我不知道添加bindingExtensions时应该在type属性中写些什么。这是我的配置:

<system.serviceModel>
<extensions>
  <bindingExtensions>
    <add name="MaxClockSkewBinding" type="Microsoft.ServiceModel.Samples.MaxClockSkewBinding, MaxClockSkewBinding,  
            Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  </bindingExtensions>
</extensions>
<bindings>
  <customBinding>
    <binding name="MaxClockSkewBinding">
      <transactionFlow />
      <security authenticationMode="SecureConversation">
        <secureConversationBootstrap authenticationMode="UserNameOverTransport">
          <localClientSettings maxClockSkew="00:30:00" />
        </secureConversationBootstrap>
        <localClientSettings maxClockSkew="00:30:00" />
      </security>
      <httpsTransport />
    </binding>
  </customBinding>

当我运行程序时,错误是:

  

找不到配置绑定扩展名'system.serviceModel / bindings / MaxClockSkewBinding'。验证此绑定扩展名已在system.serviceModel / extensions / bindingExtensions中正确注册,并且拼写正确

这就是我使用服务的方式:

channelFactory = new ChannelFactory<TProxy>("*");
            channelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;                
            //channelFactory.Credentials.ServiceCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;
            //channelFactory.Credentials.ClientCertificate.Certificate = new X509Certificate2(Certificate, CertificatePass);
            channelFactory.Credentials.UserName.UserName = UserName;
            channelFactory.Credentials.UserName.Password = PassWord;
            var proxy = (IClientChannel)channelFactory.CreateChannel();

1 个答案:

答案 0 :(得分:0)

在Visual Studio中打开Tools > WCF Service Configuration Editorenter image description here 创建新的WCF服务配置并编辑现有的配置可以为您提供很多帮助。