我正在使用 WCF 将图像从服务器连续流式传输到客户端。但是,每当我尝试运行它时,我总是会收到此错误:
位于“这里的本地主机地址”的 HTTP 服务太忙。
我在网上到处找,并尝试了其他解决方案。我尝试过节流、增加缓冲区大小和更改传输模式均无济于事。我对 WCF 很陌生,不知道还能去哪里。如果有人知道如何摆脱这个错误,我将不胜感激。谢谢!这是我所有的代码。
应用程序配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_VisionWcfInterface" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentCalls="16" maxConcurrentInstances="2147483647" maxConcurrentSessions="10"/>
</behavior>
</serviceBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:8002/Visual/service" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_VisionWcfInterface"
contract="VisionWcfInterface" name="BasicHttpBinding_VisionWcfInterface" />
</client>
</system.serviceModel>
</configuration>
Client.cs 文件和 ClientWCF 函数:
public Form1()
{
private VisionWcfClient client = new VisionWcfClient();
client.Connect();
pictureBox2.Image = ConvertByteArrayToImage(client.GetVideoStream());
}
public byte[] GetVideoStream()
{
return m_clientProxy.GetVideoStream();
}
Server.cs 文件和 ServerWCF 函数:
public byte[] GetVideoStream()
{
return GetVideoStreamEvent();
}
byte[] ads_GetVideoStreamEvent()
{
IntPtr pointer;
m_Buffers.GetAddress(out pointer);
Bitmap b = new Bitmap(m_Buffers.Width, m_Buffers.Height, m_Buffers.Pitch, System.Drawing.Imaging.PixelFormat.Format8bppIndexed, pointer);
System.Drawing.Imaging.ColorPalette palette = b.Palette;
Color[] entries = palette.Entries;
for (int i = 0; i < 256; i++)
entries[i] = Color.FromArgb(255, i, i, i);
b.Palette = palette;
m_Buffers.ReleaseAddress(pointer);
using (MemoryStream ms = new MemoryStream())
{
b.Save(ms, ImageFormat.Bmp);
return ms.ToArray();
}
}