连接到本地 Web 服务时,我不能使用自己的设备进行调试吗?

Can't I debug using my own device when connecting to local web service?

我在单独的解决方案中的 Web api 项目中有一个 Web 服务。我正在尝试从 Xamarin 项目访问该 Web 服务。我正在使用 Android phone 进行调试,但出现此错误。我遇到的所有访问 Web 服务的文章都使用模拟器。是因为这个我收到这个错误还是我错过了什么?

更新 1:
我的代码如下,错误出现在第10行(包含using (WebResponse response = await request.GetResponseAsync())的行)。

private async Task<JsonValue> GetNamesAsync()
{
    try
    {
        string  url = "http://{network-ip-address}:{port}/api/Names";
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url));
        request.ContentType = "application/json";
        request.Method = "GET";

        using (WebResponse response = await request.GetResponseAsync())
        {
                //Some code here
        }
        return null;
    }
    catch(Exception ex)
    {
        return null;
    }
}  

更新 2:
如果我 Step Into (F11),那么在大约 2 次点击后,将打开以下对话框。

您正在尝试单步执行代码:

WebResponse response = await request.GetResponseAsync()

也就是说,您正在尝试调试 HttpWebRequest class 中的 GetResponseAsync() 方法。此 class 的源代码尚未加载到您的项目中(仅已编译 .dll),因此您无法进入此行。

尝试F10跨过这条线。

您现在可能会遇到同样的错误 - 但是,这次的原因会有所不同。由于等待 GetResponseAsync() 方法,程序流返回到调用 GetNamesAsync() 的方法。如果等待该调用,并且所有等待返回 Activity 方法的对该方法的调用链(为了不阻塞 UI 应该如此),要执行的下一行代码将是 Xamarin/Android 源代码中某处的一行代码,您也无权访问。

例如

 1 class MyActivity : Activity
 2 {
 3     // This function is called by the Xamarin/Android systems and is not awaited.
 4     // As it is marked as async, any awaited calls within will pause this function,
 5     // and the application will continue with the function that called this function,
 6     // returning to this function when the awaited call finishes.
 7     // This means the UI is not blocked and is responsive to the user.
 8     public async void OnCreate()
 9     {
10         base.OnCreate();
11         await initialiseAsync(); // awaited - so will return to calling function
12                                  // while waiting for operation to complete.
13
14         // Code here will run after initialiseAsync() has finished.
15     }
16     public async Task initialiseAsync()
17     {
18         JsonValue names = await GetNamesAsync(); // awaited - so will return to Line 11
19                                              // while waiting for operation to complete.
20         
21         // Code here will run after GetNamesAsync() has finished.
22     }
23 }