简体   繁体   English

如何将base64字符串转换为二进制

[英]How to convert base64 string to binary

Clarification澄清

This question is, not a duplicate of the linked suggest as this is a UWP based issue where System.Data.Linq namespace cannot be referenced.这个问题不是链接建议的重复,因为这是一个基于UWP的问题,无法引用 System.Data.Linq 命名空间。 This was closed as a duplicate question previously however this is a different problem .这是以前作为重复问题关闭的,但是这是一个不同的问题 This isn't standard .NET, it is the Universal Windows Platform这不是标准的 .NET,而是通用 Windows 平台

How does one convert a base64 string to System.Data.Linq.Binary type within UWP.如何在 UWP 中将 base64 字符串转换为System.Data.Linq.Binary类型。

The issue is occuring when I am attempting to send data over to my WCF service which is using a linq to sql datacontext class.当我尝试将数据发送到使用 linq to sql datacontext 类的 WCF 服务时,会出现此问题。 The field in the database is the image type and the class created by the linq to sql datacontext changes the type to System.Data.Linq.Binary rather than byte[] (which is what I was using when it was a manually created class.数据库中的字段是image类型,由 linq to sql datacontext 创建的类将类型更改为System.Data.Linq.Binary而不是byte[] (这是我在手动创建类时使用的。

So far my attempts have been fruitless.到目前为止,我的尝试都没有结果。 Normally I would send it over as byte[], however if i use Convert.FromBase64String(mystring) I get the error通常我会将它作为字节 [] 发送,但是如果我使用Convert.FromBase64String(mystring)我得到错误

unable to implicitly convert byte[] to System.Data.Linq.Binary无法将 byte[] 隐式转换为 System.Data.Linq.Binary

Clarification澄清

This question is, not a duplicate of the linked suggest as this is a UWP based issue where System.Data.Linq namespace cannot be referenced.这个问题不是链接建议的重复,因为这是一个基于UWP的问题,无法引用 System.Data.Linq 命名空间。

Linq.Binary has a constructor that takes a byte[] which is available in UWP pre Windows 10. Linq.Binary 有一个构造函数,它接受一个 byte[] ,它在 Windows 10 之前的 UWP 中可用。

So in this case:所以在这种情况下:

var x = new System.Data.Linq.Binary(Convert.FromBase64String(mystring));

For windows 10 or above, you would need to change the object in the Web Service to take a byte array, by changing the Entity type.对于 Windows 10 或更高版本,您需要通过更改实体类型来更改 Web 服务中的对象以采用字节数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM