Windows 商店应用程序(旁加载)和与 REST 服务的通信
Windows Store App (sideloaded) and communication with REST services
我在 windows 8.1 平板电脑上从我的 Windows 商店应用程序(侧面加载)连接到我的 REST Web 服务时遇到一些问题。
Web 服务发布在公司服务器上,并且设备属于域,因此两个设备都在同一网络(Intranet)上。我尝试了不同的功能:
- 仅‘专用网络(客户端和服务器)
- 具有企业身份验证的专用网络
- 仅企业认证
我的代码是这样的:
using Windows.Web.Http;
private async Task SendRegistrationData()
{
using (var client = new HttpClient())
{
var baseAddress = new Uri(@"http://serverName:88/Device/RegisterDevice");
var msg = new HttpRequestMessage(new HttpMethod("POST"), baseAddress);
var serializedDevice = JsonConvert.SerializeObject(CurrentDevice.Instance);
msg.Content = new HttpStringContent(serializedDevice);
msg.Content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/json");
client.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
HttpResponseMessage response = null;
try
{
response = await client.SendRequestAsync(msg);
await Logger.LogError("Registration data were sent");
}
catch(Exception ex)
{
Logger.LogError("Communication errors", ex, 5);
Logger.LogError("HResult: " + ex.HResult.ToString());
var tmp = new CustomMessageBox();
tmp.ShowMessage("Communication error: " + ex.Message , " Communication error ");
}
}
}
重要的事情!
当我使用“高级休息客户端”(chrome 浏览器插件)从同一设备测试我的网络服务时,一切正常。我只有 LOB Windows Store 应用程序有问题。
有什么建议吗?
此致
编辑:
错误消息:无法与服务器建立连接
HResult:-2147012889
编辑 2
刚刚发生了一些新的事情。我已经像@Jon 在上一条评论中所说的那样安装了提琴手,并且发生了一些非常奇怪的事情。
启动fiddler(无需任何额外配置)
启动我的 windows 商店应用程序,它与网络服务通信,
一切正常
关闭提琴手
windows商店应用程序无法连接网络服务!?
有线索吗?
我认为这两个功能就足够了:具有企业身份验证的专用网络 - 我错了。
尽管网络服务在公司服务器上,并且我的 windows 设备已添加到公司域,但我必须在 windows 存储清单文件中设置另一个功能:Internet(客户端)
现在一切正常
此致,
马辛
我在 windows 8.1 平板电脑上从我的 Windows 商店应用程序(侧面加载)连接到我的 REST Web 服务时遇到一些问题。
Web 服务发布在公司服务器上,并且设备属于域,因此两个设备都在同一网络(Intranet)上。我尝试了不同的功能:
- 仅‘专用网络(客户端和服务器)
- 具有企业身份验证的专用网络
- 仅企业认证
我的代码是这样的:
using Windows.Web.Http;
private async Task SendRegistrationData()
{
using (var client = new HttpClient())
{
var baseAddress = new Uri(@"http://serverName:88/Device/RegisterDevice");
var msg = new HttpRequestMessage(new HttpMethod("POST"), baseAddress);
var serializedDevice = JsonConvert.SerializeObject(CurrentDevice.Instance);
msg.Content = new HttpStringContent(serializedDevice);
msg.Content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/json");
client.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
HttpResponseMessage response = null;
try
{
response = await client.SendRequestAsync(msg);
await Logger.LogError("Registration data were sent");
}
catch(Exception ex)
{
Logger.LogError("Communication errors", ex, 5);
Logger.LogError("HResult: " + ex.HResult.ToString());
var tmp = new CustomMessageBox();
tmp.ShowMessage("Communication error: " + ex.Message , " Communication error ");
}
}
}
重要的事情!
当我使用“高级休息客户端”(chrome 浏览器插件)从同一设备测试我的网络服务时,一切正常。我只有 LOB Windows Store 应用程序有问题。 有什么建议吗?
此致
编辑: 错误消息:无法与服务器建立连接
HResult:-2147012889
编辑 2 刚刚发生了一些新的事情。我已经像@Jon 在上一条评论中所说的那样安装了提琴手,并且发生了一些非常奇怪的事情。
启动fiddler(无需任何额外配置)
启动我的 windows 商店应用程序,它与网络服务通信, 一切正常
关闭提琴手
windows商店应用程序无法连接网络服务!?
有线索吗?
我认为这两个功能就足够了:具有企业身份验证的专用网络 - 我错了。
尽管网络服务在公司服务器上,并且我的 windows 设备已添加到公司域,但我必须在 windows 存储清单文件中设置另一个功能:Internet(客户端)
现在一切正常
此致, 马辛