Given the no direct tcp / socket limitation in Windows Phone 7 I was wondering what is the way that has the least performance overhead and/or can send it in the most compact way. I think I can send the data as a file using HTTP (probably with an HTTPWebRequest) and encode it as Base64, but this would increase the transfer size significantly. I could use WCF but the performance overhead is going to be large as well. Is there a way to send plain binary data without encoding it, or some faster way to do so?
-
Do you already have something coded using WCF that is too slow or are you worrying about the performance first? – Justin Niessner Apr 01 '11 at 18:53
-
I am migrating from Windows Mobile 6.5 . It originally sent stuff with WCF and it was unbearably slow, then as Base64 and it was still slow. It got pretty good with sockets and binary representations, but that is not an option anymore. So yeah, performance is known to be an issue. Actually power consumption more than performance alone. So either doing it less intensive or more compact is a win. – cloudraven Apr 01 '11 at 19:46
2 Answers
Network communication on WP7 is currently limited to HTTP only.
With that in mind you're going to have to allow for the HTTP header being included as part of the transmission. You can help keep this small by not adding any additional headers youself (unless you really have to).
In terms of the body of the message then it's up to you to keep things as small as possible.
Formatting your data as JSON will typically be smaller than as XML.
If, however, your data will always be in a specific format you could just include it as raw data. i.e. if you know that the the data will have the first n bits/bytes/characters representing one thing, then next y bits/bytes/characters represent another, etc. you could format your data without any (field) identifiers. It just depends what you need.

- 65,560
- 11
- 91
- 143
-
That sounds good, it is always in the same format. How can I send it as raw data? – cloudraven Apr 01 '11 at 19:44
-
If you want to send binary data, then certainly some people have been using raw sockets - see Connect to attached pc from WP7 by opening a socket to localhost
However, unless you want to write your own socket server, then HTTP is very convenient. As Matt says, you can include binary content in your HTTP requests. To do this, you can use the headers:
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-Length: your length
To actually set these headers, you may need to send this as a multipart message... see questions like Upload files with HTTPWebrequest (multipart/form-data)
There's some excellent sample code on AppHub forums - http://forums.create.msdn.com/forums/p/63646/390044.aspx - shows how to upload a binary photo to Facebook.
Unless your data is very large, then it may be easier to take the 4/3 hit of Base64 encoding :) (and there are other slightly more efficient encoding types too like Ascii85 - http://en.wikipedia.org/wiki/Ascii85)