我的WCF服務正在向客戶端返回約7MB的字符串格式的數據。減少WCF服務的響應時間
客戶端必須等待響應。
什麼合適的綁定,需要修改配置文件或任何其他方法,這將減少從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);
}
}
我試圖以壓縮形式發送數據,並在客戶端解壓縮,但在響應time.Below有was'nt顯著變化是客戶端配置文件
<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>
你使用流媒體嗎? – Ujjwal
我剛剛在配置文件中將傳輸模式設置爲流式傳輸。但響應時間沒有太大差別 – user1965995
如果您不想跨機器通信,則可以嘗試netNamedPipeBinding。如果你可以發佈一些演示代碼和你對觀察響應時間的觀察,那就很清楚了。 – Ujjwal