Windows Phone 7 - 如何从应用程序发送文件/向应用程序发送文件?

发布于 2024-10-18 23:47:46 字数 420 浏览 9 评论 0 原文

我正在尝试为 Windows Phone 7 编写最基本的应用程序,并且希望能够将文件(特别是 XML,以防发生任何更改)发送到我的应用程序。目前我有一个 WCF 服务设置,因此我可以通过它发送推送通知。问题是我可以通过推送通知发送的原始数据量有限制。

我的解决方案是发送初始推送通知(平铺或原始)以提醒我的应用程序我想向其发送文件,然后使应用程序以某种方式与服务器通信(顺便说一句,一切都在我的个人计算机上 - 我我只是想弄清楚事情是如何工作的) - 应用程序将从中接收/下载文件。

实现这一目标的最简单方法是什么?请注意,我不关心安全或类似的事情。

澄清 - 问题本质上是:如何将文件从服务器传输到手机或从服务器传输到手机?假设其他所有事情都已处理 - 应用程序已启动并正在运行,并且用户已授予或将授予他可能授予许可的所有可能事物的权限。

I'm trying to write the most basic application for windows phone 7 and want to be able to send files (specifically XML in case that changes anything) to my app. Currently I have a WCF service setup so I can send push notifications through it. The problem is that there is a limit on the amount of raw data I can send via a push notification.

My solution to this is to send the initial push notification (either tile or raw) to alert my application that I want to send a file to it and then make the app somehow communicate with a server (everything is on my personal computer btw - I'm just trying to figure out how things work) - from which the app will recieve/download the files.

What is the easiest way to accomplish this? Note that I'm not concerned with security or anything like that.

Clarification - the question is essentialy: how do I transfer files from/to a server to/from the phone? Assume everything else was handled - the app is up and running and the user has given or will give permissions to every possible thing he may give his permission to.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

澉约 2024-10-25 23:47:46

不幸的是,推送通知(包括 HTTP 标头)的总大小为 1kb。这意味着它不能用于发送大量数据。

不要发送整个文件,而是发送通知(原始或 toast,视情况而定),应用程序应将其视为从服务器检索新文件/数据/任何内容的触发器。当您的应用程序启动时,也可能值得检查新消息。但是,如果当您启动应用程序时,它会通知服务器它已准备好接收原始通知,并且将发送此类消息以指示有新内容可用,则可能没有必要添加此额外检查。

要将文件传输到手机或从手机传输文件,您需要使用 HttpWebRequestWebClient,因为这是在设备上使用 HTTP 的唯一方法,并且 HTTP 是当前可用于传输数据的唯一协议。

虽然 WebClient 可能看起来比 HttpWebRequest 更容易使用,但它的灵活性较差,并且会自动在 UI 线程上执行回调,如果您在后台下载文件,几乎肯定不想要这个。

无法将文件传输到连接的 PC 或从连接的 PC 传输文件,并使它们只能供您的应用程序使用。

Unfortunately, the total size of a push notification (including HTTP headers) is 1kb. This means that it can't be used to send large amounts of data.

Instead of sending the whole file, send a notification (raw or toast—as appropriate) which should be treated by the application as a trigger to go and retrieve the new file/data/whatever from the server. It may also be worth checking for new messages when your app starts. However, if when you start the app it will notify the server that it is ready to receive raw notifications and such messages will be sent indicating new content is available, it may be unnecessary to add this extra check.

To transfer files to/from the phone you will need to use either HttpWebRequest or WebClient as this is the only way to use HTTP on the device and HTTP is the only protocol currently available to transfer data.

While WebClient may appear to be easier to use than HttpWebRequest it is less flexible and will automatically perform it's callback on the UI thread and if you're downloading files in the background you almost certainly don't want this.

There is no way to transfer files to/from a conencted PC and have them exclusively available to your app.

靑春怀旧 2024-10-25 23:47:46

首先:您将无法自动执行此方法 - 用户必须打开您的应用程序才能执行此操作,因为 WP7 SDK 不允许您的应用程序在收到推送通知后在后台运行/自动启动。

此时与服务器通信的唯一方法是 Web 服务。如果我是你,我会在应用程序启动后检查可用的新信息,如果有新信息,我会调用一个或多个网络服务,这些服务会返回我需要的所有信息。
如果需要,您可以使用计时器定期检查信息。

正如我所说,它只能在您的应用程序运行时起作用(如果您还不知道,请检查应用程序生命周期),WP7 不允许应用程序在后台运行,恕我直言,这是一个严重的限制。

祝你好运,
奥斯卡

First of all: you won't be able to do this approach automatically - the user will have to open your app to do that because WP7 SDK doesn't allow your app to run on background/start automatically once a push notification is received.

The only way to communicate with your server, at this point in time, is web services. If I were you, I would check for new information available once the app is started, if there is new info, I would call one or more web services which would return me all the information that I need.
If you want, you can use a timer to check for information periodically.

As I said, it will only work while your app is running (check the app lifecycle if you don't know it yet), WP7 doesn't allow apps to run in background, that is a serious limitation IMHO.

Good Luck,
Oscar

输什么也不输骨气 2024-10-25 23:47:46

也许有点偏离主题,但当我考虑在 WP7 应用程序中共享文件时,我发现了两种方法:

  1. 将应用程序与 集成Dropbox
  2. 使用适用于 WP7 的高级浏览器

Maybe a little bit off topic but when I was thinking about file sharing in my WP7 app, I found two approaches:

  1. Integrate an app with Dropbox
  2. Use advanced explorer for WP7
梦屿孤独相伴 2024-10-25 23:47:46

You can use the WebClient class and the DownloadStringAsync method in order to download data from a web service .
A good example of this is Scott Guthrie's Twitter app from MIX10 .

George

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文