开发者

Protocol buffer net with 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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜