我的 WCF 服务以字符串格式向客户端返回大约 7MB 的数据。
客户端必须等待响应。
需要在配置文件中修改哪些适当的绑定或任何其他方法会减少 WCF 服务的响应时间?
public string GetData() //Without compression
{
return File.ReadAllText("SampleDB");
}
private string GetDataforCompression() //with compression
{
string data=File.ReadAllText("SampleDB");
Compress(data);
}
public static string Compress(string ToCompress)
{
var bytes = Encoding.UTF8.GetBytes(ToCompress);
using (var msi = new MemoryStream(bytes))
using (var mso = new MemoryStream())
{
using (var gs = new DeflateStream(mso, CompressionMode.Compress))
{
CopyTo(msi, gs);
}
return Convert.ToBase64String(mso.ToArray());
}
}
public static void CopyTo(Stream src, Stream dest)
{
byte[] bytes = new byte[4096];
int cnt;
while ((cnt = src.Read(bytes, 0, bytes.Length)) != 0)
{
dest.Write(bytes, 0, cnt);
}
}
我尝试以压缩形式发送数据并在客户端解压缩,但响应时间没有显着变化。以下是客户端配置文件
<customBinding>
<binding name="httpbinarybinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
<binaryMessageEncoding>
<readerQuotas maxDepth="4194304" maxStringContentLength="65536000" maxArrayLength="4194304" maxBytesPerRead="4194304" maxNameTableCharCount="4194304" />
</binaryMessageEncoding>
<httpTransport maxReceivedMessageSize="65536000" maxBufferSize="65536000" />
</binding>
</customBinding>