[英]TCP connection phase fails (calling web service from JAVA client to C#-server)
因此我有一个适用于Android的应用程序,该应用程序调用了Web服务(C#),从一开始我就注意到它经常但并非始终如此,返回答案的速度非常慢,或者请求完全失败。
起初,我认为这与后端代码有关,即服务器需要很长时间来处理请求并返回结果。 我现在排除了这种可能性,因为处理只需要40毫秒。 但是,我确实注意到有时不调用Web服务代码,或者执行代码需要花费很长时间。
因此,我启动了Wireshark,查看了传输的数据包,发现了我认为错误的TCP连接阶段。 下面的第一张图片显示了错误的连接。
看起来像这样:
如下图所示:
但是它应该看起来像这样:
当我再次尝试时,只要再次从Android应用程序中调用webservie(不重新启动或执行任何操作),我将获得正确的步骤,并得到预期的响应。 这是来自其中的Wireshark图像:
我非常确定这是我认为“非常缓慢的Web服务”的问题,因为在收到答案之前通常会有很长的延迟,有时(如第一张图片所示)根本没有响应。 Wireshark还显示,它只能在10-20秒内“拖延”答案,而这实际上是在重新获得Web服务代码之前。
没有网络问题,因为所有问题都在本地WLAN上运行(计算机充当热点,没有其他人与其连接)。 Android设备是运行2.3.3的Samsung S2,Web服务是运行自托管ServiceHost的.NET 3.5。
有任何想法吗?
- - - - 附加信息 - - - - - -
这是我从JAVA代码(方法是GET)中调用Web服务的方式:
private void executeRequest(HttpUriRequest request, String url)
{
HttpClient client = new DefaultHttpClient();
try
{
httpResponse = client.execute(request);
responseCode = httpResponse.getStatusLine().getStatusCode();
message = httpResponse.getStatusLine().getReasonPhrase();
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
response = convertStreamToString(instream);
// Closing the input stream will trigger connection release
instream.close();
}
} catch (ClientProtocolException e) {
client.getConnectionManager().shutdown();
e.printStackTrace();
} catch (IOException e) {
client.getConnectionManager().shutdown();
e.printStackTrace();
}
}
这是在.NET中定义Web服务方法的方式:
[OperationContract]
[WebGet(UriTemplate = "PutMessage?jsonString={jsonString}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat= WebMessageFormat.Json)]
string PutMessage(string jsonString);
如果您更仔细地查看转储,您实际上看到的是客户端没有从服务器获取任何数据包。
Client: SYN
Server: SYN ACK (ACK, never reaches the client)
Server: SYN ACK (Retransmission of the first ACK, also lost. )
Client: SYN (Retransmission, it does not know the server received the first SYN)
Server: SYN ACK (ACK on the SYN from the client, once again lost)
Client: SYN (Retransmission since it *still* does not know the server got the SYN)
换句话说,如果客户端未接收到任何服务器数据包,则从双方进行的完全正常的重新传输。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.