实体数据模型 (edmx) 服务返回 sql server 2008 图像类型作为 iPhone SDK 通过 NSURLConnection 的二进制访问

发布于 2024-08-24 19:20:27 字数 5741 浏览 7 评论 0原文

我有一个 sql 图像类型字段在 EDM(实体数据模型).NET 服务调用中返回。图像字段在 sql server 2008 中以二进制形式存储。但是,我不确定图像数据发生了什么,或者编码类型是什么。由于网络服务是在幕后生成的,因此在通过网络发送图像二进制数据之前,我无法弄清楚该服务是否对图像二进制数据做了一些奇怪的事情。

有人做过类似的事情吗?

我尝试过对图像进行base64解码,尝试将NSURLConnection请求编码设置为NSUTF8StringEncoding,但都没有成功

这是一个示例数据包嗅探:

HTTP/1.1 200 OK 日期:2010 年 3 月 9 日星期二 19:41:13 GMT 服务器:微软-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-版本:2.0.50727 数据服务版本:1.0; 缓存控制:无缓存 内容类型:application/json;charset=utf-8 内容长度:41809

{“d”:[ { “__元数据”:{ "uri": "http://11.111.11.111:8002/domain /myservice.svc/StudentByGroupID(createDate=datetime\'2009-12-15T11%3A16%3A18.14\',firstName=\'年松\',groupId=1,isActive=1,lastName=\'刘\',studentGroupId=28,studentId=6)", "type": "MyModel.StudentByGroupID" }, "studentId": 6, "firstName": "念松", "lastName": "刘", "createDate": "/Date(1260875778140)/", "updateDate": null, "isActive": 1, " image": "AAEAAAD/////AQAAAAAAAAAMAgAAAFFTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0yLjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRtYXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAABA0AAAL/2P/gABBKRklGAAEBAAABAAEAAP/bAEMACQYHCAcGCQgHCAoKCQsNFg8NDAwNGxQVEBYgHSIiIB0fHyQoNCwkJjEnHx8tPS0xNTc6OjojKz9EPzhDNDk6N//bAEMBCgoKDQwNGg8PGjclH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EBHIL7FJyMjv1oorCt8BtR+I//2Qs=”,“studentGroupId”:28,“groupId”:1 } ] }

I have a sql image type field coming back in an EDM (Entity Data Model) .NET service call. The image field is stored as binary in sql server 2008. However, I'm not sure what is happening to the image data, or what type of encoding. And since the webservices are generated behind the scenes, I can’t figure out if the service is doing something funky to the image binary data before sending it across the wire.

Anyone done anything of the sort?

I've tried base64 decoding the image, tried setting the NSURLConnection request encoding to NSUTF8StringEncoding, all with no luck

Here's a sample packet sniff:

HTTP/1.1 200 OK
Date: Tue, 09 Mar 2010 19:41:13 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
DataServiceVersion: 1.0;
Cache-Control: no-cache
Content-Type: application/json;charset=utf-8
Content-Length: 41809

{ "d" : [
{
"__metadata": {
"uri": "http://11.111.11.111:8002/domain/myservice.svc/StudentByGroupID(createDate=datetime\'2009-12-15T11%3A16%3A18.14\',firstName=\'Niansong\',groupId=1,isActive=1,lastName=\'Liu\',studentGroupId=28,studentId=6)", "type": "MyModel.StudentByGroupID"
}, "studentId": 6, "firstName": "Niansong", "lastName": "Liu", "createDate": "/Date(1260875778140)/", "updateDate": null, "isActive": 1, "image": "AAEAAAD/////AQAAAAAAAAAMAgAAAFFTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0yLjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRtYXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAABA0AAAL/2P/gABBKRklGAAEBAAABAAEAAP/bAEMACQYHCAcGCQgHCAoKCQsNFg8NDAwNGxQVEBYgHSIiIB0fHyQoNCwkJjEnHx8tPS0xNTc6OjojKz9EPzhDNDk6N//bAEMBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3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WUXrqdVaC9m0uhzqNirEUmGFVAaej81o0cCZu+eTpt0uesLDr7GpNOYtqkQBILQqP0asqOb9xKp7xsMfhV7TJUXULJmIAaLknHo1claGjOmlLVEjX943L3cxPvIaj82VvvSuR7saE0rVn+7pt4fpA3+FTr4f15/u6TefjERVciGplZpJCp+djxx8xr1iytxHsVuEjVYwPXaAP6V5zF4Y8QEgnSbgAHncAP616Nc3UWnWtxql02FjJ8oepzxitKcUrmkZXWhyXjHUS+rT2a4KTFVYKMkMOB36YxWAql7iSJn3LEoTAweBx69wKl3Mbk6heuI5ppCI1Pbgk/p/MVSgYs905+bL4Xdz3z/St6CesjPFOzUew43NzHPIjTsQRx8oAOOmOKoSXMrTBNxx34q9MqlVYcsQRkdsZ/wrMJ2yMSMN27jrWzVjjbK95PIxVAx3Kepx7Yqhc7/MPXOKutjyyx5JJFV2AMse0DoRxUEM6qBZNTubeaQ7ooERBz14BP8AMVb8XfvLFgB9zafphgP61n+D3Z4pIgfvjeM9iOD/AErT1rM2mzqVw/lsDn2GQf0rl2keuvfot9zic0oOGpmaaSwzjk1ueVctJKBkM3UYqe2mZhaMDjEZwfx/+vVS2+yMw+2faQf9jH+FaUcGjbFHmaiNowBsBArKpbZo1p36M2JPFGuvw+qXOD285h/Kqr61qT58zUp29mmc/wBaKKzUUza9iJLq4nkWNJ9zyMFUHPJPA6n3rvtSkF7dRfahm3iiMsUI6Y/vn3Y9B2HXnoUU+RRWh04eTle5xUpe4vbd52+d2LRgdEABOfxI/KhFkhXI+bcOSD3/AP1Giiuql8JyV9ZsJtqxY2HeWJJfnnOeBkgdaz7hFMucZ5+X8/8A9VFFaNHOUpQqx7CD6n8qrMpMg55yQAfWiioJOg8JsXtg8OBcQyMy56OuRkH8/wBa3NRkWZEZOFkJ3KR/n1oorm+0etR/hI4DpgUoIoorY8ok2hsAitzQRGtpGZEBHIL7FJyMjv1oorCt8BtR+I//2Qs=", "studentGroupId": 28, "groupId": 1
}
] }

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

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

发布评论

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

评论(2

哆啦不做梦 2024-08-31 19:20:27

该返回是 JSON 有效负载 (application/json),其中包含 UTF-8 上的 Base64 编码图像8 字符集。如果您不想自己解析 JSON,可以使用 json-framework 您可以尝试,或者 TouchJSON

That return is a JSON payload (application/json) with a base64 encoded image on a UTF-8 charset. If you don't want to parse JSON on your own, there is json-framework you could try, or TouchJSON.

美人迟暮 2024-08-31 19:20:27

这是.net图像相关代码:

Codes for saving images into database
System.Drawing.Image img = System.Drawing.Image.FromFile(imgPath);// “imgPath” is the file path of a temporary image uploaded by a user.
student.image = new System.Data.Linq.Binary(Utility.Convertor.ImageToByteArray(img));
img.Dispose();
Codes for writing image bytes from server to client
System.Drawing.Image img = Utility.Convertor.ByteArrayToImage(stu.image.ToArray());
Response.ContentType = ("image/" + Utility.Gadget.GetImageFormat(img));
MemoryStream ms = new MemoryStream();
img.Save(ms, img.RawFormat);
byte[] result = ms.ToArray();
ms.Close();
ms.Dispose();
Response.BinaryWrite(result);

Below are encapsulated methods for storing / restoring students’ images:
Serializer for serializing a image to bytes
/// 
/// Convert a System.Drawing.Image object to byte array formatted by System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.
/// 
/// 
/// 
public static byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
      BinaryFormatter sf = new BinaryFormatter();
      MemoryStream ms = new MemoryStream();
      sf.Serialize(ms, imageIn);
      byte[] result = ms.ToArray();
      ms.Close();
      ms.Dispose();
      return result;
}
Deserializer for restoring a image from bytes
/// 
/// Convert a byte array formatted by System.Runtime.Serialization.Formatters.Binary.BinaryFormatter to a System.Drawing.Image object.
/// 
/// 
/// 
public static System.Drawing.Image ByteArrayToImage(byte[] byteArrayIn)
{
       BinaryFormatter sf = new BinaryFormatter();
       MemoryStream ms = new MemoryStream(byteArrayIn);
       System.Drawing.Image returnImage = (System.Drawing.Image)sf.Deserialize(ms);
       ms.Close();
       ms.Dispose();
       return returnImage;
}

Here is the .net image related code:

Codes for saving images into database
System.Drawing.Image img = System.Drawing.Image.FromFile(imgPath);// “imgPath” is the file path of a temporary image uploaded by a user.
student.image = new System.Data.Linq.Binary(Utility.Convertor.ImageToByteArray(img));
img.Dispose();
Codes for writing image bytes from server to client
System.Drawing.Image img = Utility.Convertor.ByteArrayToImage(stu.image.ToArray());
Response.ContentType = ("image/" + Utility.Gadget.GetImageFormat(img));
MemoryStream ms = new MemoryStream();
img.Save(ms, img.RawFormat);
byte[] result = ms.ToArray();
ms.Close();
ms.Dispose();
Response.BinaryWrite(result);

Below are encapsulated methods for storing / restoring students’ images:
Serializer for serializing a image to bytes
/// 
/// Convert a System.Drawing.Image object to byte array formatted by System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.
/// 
/// 
/// 
public static byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
      BinaryFormatter sf = new BinaryFormatter();
      MemoryStream ms = new MemoryStream();
      sf.Serialize(ms, imageIn);
      byte[] result = ms.ToArray();
      ms.Close();
      ms.Dispose();
      return result;
}
Deserializer for restoring a image from bytes
/// 
/// Convert a byte array formatted by System.Runtime.Serialization.Formatters.Binary.BinaryFormatter to a System.Drawing.Image object.
/// 
/// 
/// 
public static System.Drawing.Image ByteArrayToImage(byte[] byteArrayIn)
{
       BinaryFormatter sf = new BinaryFormatter();
       MemoryStream ms = new MemoryStream(byteArrayIn);
       System.Drawing.Image returnImage = (System.Drawing.Image)sf.Deserialize(ms);
       ms.Close();
       ms.Dispose();
       return returnImage;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文