gpt4 book ai didi

c# - 从 wcf ksoap2 接收字节 [] 到 android 时遇到问题

转载 作者:行者123 更新时间:2023-11-30 03:10:08 25 4
gpt4 key购买 nike

我正在尝试将图像从 wcf ksoap2 发送到 android。在 wcf 端,我已将所有图像转换为字节数组并将它们存储在 ArrayList 中。在 android 端,我尝试填充 ArrayList<Byte> arrays;但它没有填充,它仍然是空的。这是我的代码

wcf:

        List<byte[]> list;
public List<byte[]> loadImages()
{
DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Users\User\Desktop\abc");
arr1 = new ArrayList();
foreach (FileInfo fi in directoryInfo.GetFiles())
arr1.Add(fi.FullName);



list = new List<byte[]>();
for (int i = 0; i < arr1.Count; i++)
{
img = Image.FromFile(arr1[i].ToString());
ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
list.Add(ms.ToArray());
// objbyte = (byte[])ms.ToArray();
}

return list;
}

安卓:

            SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope soapEnvelop;
soapEnvelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelop.dotNet = true;
soapEnvelop.setOutputSoapObject(Request);
HttpTransportSE htps = new HttpTransportSE(URL);

htps.call(SOAP_ACTION, soapEnvelop);
response = (SoapObject) soapEnvelop.getResponse();
ar = new String[response.getPropertyCount()];

arrays = new ArrayList<Byte>();

if (response != null) {

if (response.getPropertyCount() > 0) {

for (int i = 0; i < response.getPropertyCount(); i++) {

arrays.add( (Byte) response.getProperty(i));
}
}
}

for 循环正确执行但 arrays仍然是空的

我想一次发送 10-15 张图片。提前致谢

最佳答案

代码如下:

SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope soapEnvelop;
soapEnvelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelop.dotNet = true;
soapEnvelop.setOutputSoapObject(Request);
HttpTransportSE htps = new HttpTransportSE(URL);

htps.call(SOAP_ACTION, soapEnvelop);
response = (SoapObject) soapEnvelop.getResponse();
ar = new String[response.getPropertyCount()];

arrays = new ArrayList<Byte>();

if (response != null) {

if (response.getPropertyCount() > 0) {

for (int i = 0; i < response.getPropertyCount(); i++) {

arrays.add( (Byte) response.getProperty(i));
}
}
}

关于c# - 从 wcf ksoap2 接收字节 [] 到 android 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21115575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com