Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我的异步回调需要几分钟?(在Win CE 5.0条形码扫描仪上使用Compact Framework 3.5)_C#_.net_Httpwebrequest_Compact Framework_Windows Ce - Fatal编程技术网

C# 为什么我的异步回调需要几分钟?(在Win CE 5.0条形码扫描仪上使用Compact Framework 3.5)

C# 为什么我的异步回调需要几分钟?(在Win CE 5.0条形码扫描仪上使用Compact Framework 3.5),c#,.net,httpwebrequest,compact-framework,windows-ce,C#,.net,Httpwebrequest,Compact Framework,Windows Ce,几天前,我开始使用Compact Framework 3.5为运行在C#中WinCE 5.0上的条形码扫描仪编码。我很难让我的异步HttpWebRequest完成它应该做的事情。(特别是因为它是CF3.5…)现在它可以工作了。。。但完成请求需要1-3分钟 private void xmlRequestButton_Click(object sender, EventArgs e) { System.Uri myUri = new System.Uri("http://www.mydoma

几天前,我开始使用Compact Framework 3.5为运行在C#中WinCE 5.0上的条形码扫描仪编码。我很难让我的异步HttpWebRequest完成它应该做的事情。(特别是因为它是CF3.5…)现在它可以工作了。。。但完成请求需要1-3分钟

private void xmlRequestButton_Click(object sender, EventArgs e)
{
    System.Uri myUri = new System.Uri("http://www.mydomain.de/someFolder/index.php");
    HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(myUri);
    myRequest.Method = "POST";
    myRequest.ContentType = "text/html";
    myRequest.SendChunked = true;

    myRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), myRequest);
}

private static void GetRequestStreamCallback(IAsyncResult callbackResult)
{
    HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
    Stream postStream = myRequest.EndGetRequestStream(callbackResult);

    string postData = "testparam=testvalue";
    byte[] byteArray = Encoding.UTF8.GetBytes(postData);

    postStream.Write(byteArray, 0, postData.Length);
    postStream.Close();

    myRequest.BeginGetResponse(new AsyncCallback(GetResponsetStreamCallback), myRequest);
}

private static void GetResponsetStreamCallback(IAsyncResult callbackResult)
{
    HttpWebRequest request = (HttpWebRequest)callbackResult.AsyncState;
    HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(callbackResult);

    Stream streamResponse = response.GetResponseStream();
    StreamReader streamRead = new StreamReader(streamResponse);
    string responseString = streamRead.ReadToEnd();
    Console.WriteLine(responseString);

    streamResponse.Close();
    streamRead.Close();

    response.Close();
    allDone.Set();
}
每次访问我的Web服务时都会记录日志。它只是在呼应“成功”。起初我认为WebRequest根本不起作用。但是,当我意外地停止调试一段时间后,我意识到它起了作用,但只是花了很长时间。该设备甚至将答案“success”记录到控制台上。 那怎么会花这么长时间呢?我遗漏了什么吗


我的目标是设备扫描一些条形码,然后联系Web服务,该服务会返回产品名称和其他信息。

为什么要使用此SCU客户端?此CE5设备上是否没有预装合适的设备(哪种型号?)

您使用的服务器是否可以通过Internet或Intranet访问?看起来您有TCP/IP DNS或路由问题。请尝试vxUtils(剑桥软件免费版)ping等来验证连接

您知道您的电脑可能被设备用于互联网连接(ActiveSync/WMDC passthru)。 请在没有活动ActiveSync/WMDC连接的情况下尝试TCP/IP(以及您的应用程序)。在第一次部署/调试会话启动后,您仍然可以进行调试,因为VS会记住设备的IP地址并将其用于后续会话,即使设备未连接到USB(WMDC)。另请参见Visual Studio SmartDevice远程调试


如果您没有发现网络问题,请返回您的详细调查结果。

设备如何连接到互联网(WiFi、手机数据等)?哦,对不起,忘记了:它是通过WiFi连接的,完全信号强度。您是否验证了web服务不是问题所在,例如使用SoapUI测试它,一个小的测试程序或类似的东西?也许Webservice是个错误的词。稍后我将把它连接到一些Web服务。现在我将请求发送到一个记录请求数据的PHP文件。(通过浏览器访问+获取包含数据的工作。当扫描仪执行请求时,除了花费很长时间外,没有请求数据)可能有问题?这可能是web请求中的超时。我会大大降低超时值,看看它是否返回得更快。另外,请尝试并验证您可以从设备访问php文件而不会出现问题。例如,在设备上使用web浏览器。