尝试向 WCF 添加 GZip 压缩时,CustomBinding 缺少 TransportBindingElement

CustomBinding lacks a TransportBindingElement when trying to add GZip compression to WCF

我正在尝试将 GZip 添加到我的 WCF 服务的绑定中,但出现下一个错误

The Scheme cannot be computed for this binding because this CustomBinding lacks a TransportBindingElement.  Every binding must have at least one binding element that derives from TransportBindingElement.

我的网络配置包含以下内容:

 <bindings>
      <customBinding>
        <binding name="BinaryCompressionBinding">
          <binaryMessageEncoding compressionFormat ="GZip"/>
          <httpTransport />
        </binding>
      </customBinding>
      <webHttpBinding>
        <binding closeTimeout="00:10:00" transferMode="StreamedResponse" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="myServiceBehavior" name="SMS.Example.Service">
        <endpoint address="" behaviorConfiguration="customBinding" binding="customBinding" name="customBinding" contract="SMS.Example.IService"/>
        <endpoint address="mex" binding="mexHttpBinding" name="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>

可能是什么原因造成的?

您的端点节点有问题。缺少绑定配置属性。添加 bindingConfiguration="BinaryCompressionBinding" 并重试。