【发布时间】:2021-05-13 01:01:52
【问题描述】:
我一直在网上查找,但找不到定义的过程或有关如何配置基本 HTTP 自托管 WCF 服务以压缩服务器发送给客户端的消息的示例。
我想使用 GZIP 或类似技术。
这是我的应用程序 app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<services>
<service name="Application.ApplicationServicesProxy" behaviorConfiguration="ApplicationSvcsBehave">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9001/ApplicationSvcs"/>
</baseAddresses>
</host>
<endpoint address="http://localhost:9001/ApplicationSvcs" binding="basicHttpBinding" contract="Application.IApplicationServices"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ApplicationSvcsBehave">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
这就是我创建服务的方式:
var host = new ServiceHost(typeof(ApplicationServicesProxy));
host.Open();
服务在 IApplicationServices 中定义,由 ApplicationServicesProxy 继承
[ServiceContract]
interface IApplicationServices
{
[OperationContract]
string[] MethodOne();
}
public class AppicationServicesProxy : IApplicationServices
{
public string[] MethodOne()
{
// return a string value;
}
}
这就是我将客户端连接到服务的方式
var ApplicationSvcs = new ApplicationSvcs.ApplicationServicesClient("BasicHttpBinding_IApplicationServices");
我目前使用的是 .NET 4.8
【问题讨论】:
-
我们可以在自定义绑定中设置compressionFormat为Gzip,这个也有类似的问题,可以参考:stackoverflow.com/questions/15680087/…