Windows Phone 7 的协议缓冲网络

发布于 2024-09-09 09:22:19 字数 966 浏览 7 评论 0原文

我正在尝试从 Windows Phone 7 应用程序中的协议缓冲区格式的服务器下载响应。

我正在尝试使用 WebClient 来执行此操作,我的问题如下。

WebClient 只有两种下载方法

DownloadStringAsync(new Uri(url));

OpenReadAsync(new Uri(url));

但这两种方法不能很好地检索响应,因为响应大小应该有 16 个十六进制字符( 080118CBDDF0E104 ),但这两种方法获取的字符串和流的大小仅为8.

所以我正在寻找一种方法来解决我的问题。 我找到了一个 C#

public static T DownloadProto<T>(this WebClient client, string address)
{
   byte[] data = client.DownloadData(address);
   using (var ms = new MemoryStream(data))
   {
      return Serializer.Deserialize<T>(ms);
   }
}

http://code.google.com/p/protobuf-net/source/browse/trunk/BasicHttp/HttpClient/ProtoWebClient.cs?spec=svn340&r=340

但该方法已被删除或尚未实现在 Windows Phone 7 开发套件上。

I'm trying to download a response from a server wich is in Protocol Buffer format from a Windows Phone 7 application.

I'm trying to do this with a WebClient, my problem is the following.

The WebClient has only two method for downloading

DownloadStringAsync(new Uri(url));

and

OpenReadAsync(new Uri(url));

but this two method are not good to retrieve the response because, the response size should have 16 hexadecimal caracteres ( 080118CBDDF0E104 ), but the size of the string and the stream get by the two methods are only 8.

So I'm searching a way to resolve my problem.
I found one for C#

public static T DownloadProto<T>(this WebClient client, string address)
{
   byte[] data = client.DownloadData(address);
   using (var ms = new MemoryStream(data))
   {
      return Serializer.Deserialize<T>(ms);
   }
}

on
http://code.google.com/p/protobuf-net/source/browse/trunk/BasicHttp/HttpClient/ProtoWebClient.cs?spec=svn340&r=340

But this method was deleted or not yet implemented on the Windows Phone 7 development kit.

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

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

发布评论

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

评论(1

忆梦 2024-09-16 09:22:19

您如何从流中读取内容?

如果您将其作为字符串读取,那么它可能每个字符读取两个字节 - 相反使用

var buf = new byte[16];
var actual = stream.Read(buf, 0, buf.Length);

How are you reading from the stream?

If you are reading it as a string then its perhaps reading two bytes per character - instead use

var buf = new byte[16];
var actual = stream.Read(buf, 0, buf.Length);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文