在WCF SOAP(客户端,传出消息)中启用http压缩

时间:2016-04-21 07:52:12

标签: .net wcf http soap compression

我必须为SOAP服务实现一个客户端,它需要使用标准的http压缩来传输数据。服务器端由第三方提供,因此不在我的控制之下!我正在使用.Net 4.5和c#。 这项任务在开始时听起来很简单,但我还没有能够启用http压缩。

由于服务使用WS-Security,我使用WCF来处理连接和所有安全性。基本上代码看起来像这样:

public void deliverMessage(obj myMessage)
{
    _client = new MyClient("BindingName"); //System.ServiceModel.ClientBase
    _client.ClientCredentials.ClientCertificate.SetCertificate((StoreLocation)_privCertLoc, (StoreName)_privCertStore, X509FindType.FindBySubjectName, _privCertName);
    _client.ClientCredentials.ServiceCertificate.SetDefaultCertificate((StoreLocation)_pubCertLoc, (StoreName)_pubCertStore, X509FindType.FindBySubjectName, _pubCertName);
    _client.DeliverData(myMessage);
}

Binding是一个CustomBinding(由于WS-Security),它使用httpsTransport。以下是相应的部分:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="SOAPBindingName">
          <security defaultAlgorithmSuite="Default" authenticationMode="MutualCertificate" requireDerivedKeys="false" includeTimestamp="true" messageProtectionOrder="SignBeforeEncrypt" messageSecurityVersion="WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10" requireSignatureConfirmation="false" allowSerializedSigningTokenOnReply="true">
            <localClientSettings detectReplays="true" />
            <localServiceSettings detectReplays="true" />
          </security>
          <textMessageEncoding messageVersion="Soap11" />
          <httpsTransport />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="https://localhost:1234/WebService/services/MyService" binding="customBinding" bindingConfiguration="SOAPBindingName" contract="ServiceReference.Contract" name="BindingName" >
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

我发现了很多关于压缩的文章,但是他们都直接使用HttpWebRequest进行调用,或者他们在消息中使用压缩而不是在传输层。 HttpWebRequest将让我为我的对象创建所有需要的安全性东西(现在由WCF处理)。传输级别以下的压缩意味着,它不可互操作,因此在我的情况下无法使用。

无需压缩即可传输数据。我很高兴能在http传输层上启用压缩的任何帮助!

0 个答案:

没有答案