我尝试在高延迟/低带宽网络上制作WCF网络服务,但事情并没有按计划进行。 WCF服务在Windows服务中自托管,实现此接口:
[OperationContract(Name = "send-file")]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
void SendFile(MyFileInfo myFile);
MyFileInfo对象包含文件(作为字节数组)。该文件大约为45 kB(千字节)。
正在使用TLS,包括客户端和服务器身份验证(来自同一域的相同CA,客户端和服务器的证书)。
在客户端和服务器上将ServicePointManager.SecurityProtocol设置为SecurityProtocolType.Tls12,将Expect100Continue设置为true,并在绑定传输元素上以编程方式将KeepAlive设置为true。
App.config在这里(对于客户端和服务器也一样):
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyHttpsBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" messageEncoding="Text"
hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="104857600" maxReceivedMessageSize="104857600"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="104857600" maxArrayLength="104857600" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
<security mode="Transport">
<transport clientCredentialType="Certificate" proxyCredentialType="None" />
<message clientCredentialType="None" ></message>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service
name="MyService"
behaviorConfiguration="MyHttpsBehavior">
<endpoint binding="wsHttpBinding"
bindingConfiguration="MyHttpsBinding" name="MyEndpoint"
contract="IMyInterface">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyHttpsBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="ChainTrust"/>
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
在标准本地网络(WLAN或以太网,MTU始终设置为1248)上一切正常,但当我切换到(模拟)高延迟/低带宽网络时出现错误:
首先,我的app.conf超时设置设置为1分钟,客户端抛出一个可靠的System.TimeoutException:&#34;请求通道在00:00之后等待回复时超时:59.1535069 。增加传递给Request的调用的超时值或增加Binding上的SendTimeout值。分配给此操作的时间可能是较长超时的一部分。 ---&GT; System.TimeoutException:对&#39; https://myserver:4444/&#39;的HTTP请求已超过00:01:00分配的超时。分配给此操作的时间可能是较长超时的一部分。&#34;
服务器上没有错误。
如果我做数学,文件是45 kb = 46080 b~&gt; 37个分组(MTU和分段)=&gt; 37 * 1600(延迟)=最少1分钟(加上TLS,加上有效载荷,再加......)
我将客户端和服务器上的超时设置更改为5分钟,并弹出新的客户端异常:&#34; System.ServiceModel.Security.SecurityNegotiationException:无法为SSL / TLS安全通道建立信任关系有权威&#39; myserver:4444&#39;&#34;
客户端和服务器可能是Windows 8或Windows 2008 R2,防火墙已关闭,如果我停止延迟模拟器(Clumsy),一切正常。
我发现TLS问题比WCF更多,但我不是专家。也许你们其中一个人对这个问题有所了解?
提前致谢!
DJ
修改 我尝试了Wireshark会话(客户端视图),结果如下:
2 26.958440 client -> server TCP 66 64972 → 4444 [SYN] Seq=0 Win=8192 Len=0 MSS=1208 WS=256 SACK_PERM=1
3 26.958603 server -> client TCP 66 4444 → 64972 [SYN, ACK] Seq=0 Ack=1 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1
4 28.606141 client -> server TCP 54 64972 → 4444 [ACK] Seq=1 Ack=1 Win=66304 Len=0
5 28.606359 client -> server TCP 276 64972 → 4444 [PSH, ACK] Seq=1 Ack=1 Win=66304 Len=222
6 28.610326 server -> client TCP 1262 4444 → 64972 [ACK] Seq=1 Ack=223 Win=66304 Len=1208
7 28.610328 server -> client TCP 711 4444 → 64972 [PSH, ACK] Seq=1209 Ack=223 Win=66304 Len=657
8 30.277053 client -> server TCP 54 64972 → 4444 [ACK] Seq=223 Ack=1866 Win=61440 Len=0
9 30.277177 client -> server TCP 236 64972 → 4444 [PSH, ACK] Seq=223 Ack=1866 Win=61440 Len=182
10 30.279375 server -> client TCP 161 4444 → 64972 [PSH, ACK] Seq=1866 Ack=405 Win=66048 Len=107
11 31.920922 client -> server TCP 331 64972 → 4444 [PSH, ACK] Seq=405 Ack=1973 Win=61440 Len=277
12 31.921599 server -> client TCP 139 4444 → 64972 [PSH, ACK] Seq=1973 Ack=682 Win=65792 Len=85
13 32.249867 client -> server TCP 1262 64972 → 4444 [ACK] Seq=682 Ack=1973 Win=61440 Len=1208
14 32.250099 client -> server TCP 1262 64972 → 4444 [ACK] Seq=1890 Ack=1973 Win=61440 Len=1208
15 32.250226 server -> client TCP 60 4444 → 64972 [ACK] Seq=2058 Ack=3098 Win=66304 Len=0
16 32.250437 client -> server TCP 1262 64972 → 4444 [ACK] Seq=3098 Ack=1973 Win=61440 Len=1208
17 32.250699 client -> server TCP 1262 64972 → 4444 [ACK] Seq=4306 Ack=1973 Win=61440 Len=1208
18 32.250816 server -> client TCP 60 4444 → 64972 [ACK] Seq=2058 Ack=5514 Win=66304 Len=0
19 33.623716 client -> server TCP 54 64972 → 4444 [ACK] Seq=5514 Ack=2058 Win=61440 Len=0
... lots of similar packets ...
89 37.189910 client -> server TCP 1262 64972 → 4444 [ACK] Seq=61082 Ack=2058 Win=61440 Len=1208
90 37.190103 client -> server TCP 1262 64972 → 4444 [ACK] Seq=62290 Ack=2058 Win=61440 Len=1208
91 37.190260 server -> client TCP 60 4444 → 64972 [ACK] Seq=2058 Ack=63498 Win=53760 Len=0
92 37.190303 client -> server TCP 1262 64972 → 4444 [ACK] Seq=63498 Ack=2058 Win=61440 Len=1208
93 37.190499 client -> server TCP 1262 64972 → 4444 [ACK] Seq=64706 Ack=2058 Win=61440 Len=1208
94 37.190654 server -> client TCP 60 4444 → 64972 [ACK] Seq=2058 Ack=65914 Win=51200 Len=0
95 37.190699 client -> server TCP 1262 64972 → 4444 [PSH, ACK] Seq=65914 Ack=2058 Win=61440 Len=1208
96 37.190890 client -> server TCP 865 64972 → 4444 [PSH, ACK] Seq=67122 Ack=2058 Win=61440 Len=811
97 37.191046 server -> client TCP 60 4444 → 64972 [ACK] Seq=2058 Ack=67933 Win=49152 Len=0
98 160.241458 server -> client TCP 60 4444 → 64972 [RST, ACK] Seq=2058 Ack=67933 Win=0 Len=0
98数据包(RST ACK)与客户端上的异常完全同时弹出。服务器上仍然没有错误。