BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 04-15-2008, 09:24 AM   #1
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Default Send byte[] to web Service

Please Login to Remove!

Hello everyone,

I try to send pictures to a web service.

I made a method that works fine on the simulator but is very heavy and when I launched it on the BB , it's doesn't work at all.

To resume , I recover the picture in a ByteArrayOutpusTream that I translate into a String and send it.

Now I now that using a SoapPrimitive will allow me to send directly a byte().

My question is how can I do that??

On a FAQ I found this :

"Can I send (and receive) objects of type byte[] with kSOAP?
Yes, there are two options. One option is to to create an intermediate SoapPrimitive object, encapsulating the byte array:

new SoapPrimitive
(Soap.ENC, "base64", Base64.encode (myByteArray));


The SoapPrimitive object can be used in conjunction with SoapObjects or the getProperty() method of KvmSerializable. For receiving byte arrays, the corresponding base64 encoded string contained in the SoapPrimitive object must me decoded using the method Base64.decode().

The other option is to use the optional MarshalBase64 class in the package org.ksoap.marshal, available separately in the download section. In most cases, it should be activated using the like shown in the example below:

ClassMap cm = new ClassMap ();
new MarshalBase64.register (cm);
myHttpTransport.setClassMap (cm);"

But I don't understand how to use this.

Thanks
Offline  
Old 04-17-2008, 03:06 AM   #2
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Default

No one have an idea or just a clue???
Offline  
Old 04-18-2008, 02:12 AM   #3
Happe79
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 8800
PIN: N/A
Carrier: IT
Posts: 21
Default

From my point of view, it is better to build an upload-site or a socket connection.

It often depends on the wsdl. I had the same problem and I was not able to solve that problem using webservices (I used an upload-site).


CU Happe
Offline  
Old 04-18-2008, 03:01 AM   #4
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Default

Hum I think the same thing.

But when we have a socket we have to have a server program runing on a server and it's what i want to avoid
Offline  
Old 04-19-2008, 01:58 AM   #5
Happe79
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 8800
PIN: N/A
Carrier: IT
Posts: 21
Default

And your webservice? Is that not running on a server?

Happe
Offline  
Old 04-19-2008, 05:15 AM   #6
bdowling
Thumbs Must Hurt
 
Join Date: Jan 2007
Model: 8800
Carrier: Orange
Posts: 181
Default

Sending it via SOAP is probably what is slowing everything down, not converting it to a string. Create a simple script on your webserver that accepts the bytes and constructs the image.
Offline  
Old 04-23-2008, 07:22 AM   #7
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

I'm using a web service to transmit binary data.

using kSOAP on the BB it looks like this:

PHP Code:
SoapObject soap_Desc = new SoapObject("","Desc");
...
SoapObject rpc = new SoapObject(Predefined.getNameSpace(), Predefined.getWebMethod());
rpc.addProperty("Desc"soap_Desc);
rpc.addProperty("data", new SoapPrimitive (SoapEnvelope.ENC"base64"packet_data));
rpc.addProperty("size", new Integer(packet_data.length()));
...
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        
envelope.bodyOut rpc;
... 
On the server side your WS function must have a String - parameter (data) which will get your Base64 encoded string and decode it back to a byte array (e.g. Convert.FromBase64String() in .net)


btw. you don't have to use the Base64 class of kSOAP, use RIM's Base64OutputStream:
PHP Code:
// copy the next piece of data to send
bytexxx91;xxx93; requestData Arrays.copy(data, (i-1)*max_packet_lengthpacket_length);
// ... and encode it to Base64 String            
String stringData Base64OutputStream.encodeAsString(requestData,0,requestData.length,false,false); 
what you also see is that you have to split your data in small packets (I use 30k blocks), otherwise you will get problems transmitting large data (keep in mind that Base64 encoded byte array increases it's size by approx. 33%)
Offline  
Old 04-28-2008, 09:17 AM   #8
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Default

All rights.

Thans for your answer.

It's what I found :

Standard mappings from WSDL to Java
xsd:base64Binary => byte[]
xsd:boolean => boolean
xsd:byte => byte
xsd:dateTime => java.util.Calendar
xsd:decimal => java.math.BigDecimal
xsd:double => double
xsd:float => float
xsd:hexBinary => byte[]
xsd:int => int
xsd:integer => java.math.BigInteger
xsd:long => long
xsd:QName => javax.xml.namespace.QName
xsd:short => short
xsd:string => java.lang.String

So as I suppose my problem come from that I try to send just byte without serialize it

Last edited by goulamass; 04-28-2008 at 09:18 AM..
Offline  
Old 09-30-2008, 04:11 AM   #9
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Default

Just one more question.

My web service is waiting for base64Binary.

So is new SoapPrimitive (SoapEnvelope.ENC, "base64", packet_data)); the same format???

If yes it will be perfect
Offline  
Old 10-01-2008, 07:54 AM   #10
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Default

All right.

Now it's works.

Thanks for your answer
Offline  
Old 11-11-2008, 06:53 AM   #11
amolsarmalkar
New Member
 
Join Date: Oct 2008
Model: 9000
PIN: N/A
Carrier: AT &T
Posts: 4
Default file post through HTTP to ASP

Hi all,

CAn anybody please explain me how to post a file to ASP page?

I have reached very close to solution as I am able to post text data ,
but in case of file
asmall change is required in http headers and probably encoding of data.
If required I will post my code here.
Offline  
Old 04-09-2009, 04:46 PM   #12
temge
New Member
 
Join Date: Apr 2009
Model: 9000
PIN: N/A
Carrier: AT&T
Posts: 1
Default

so if I have a larger byte[] of lets say 250 k, how do I submit that to a web service?

I think I might be missing something in sending smaller chunks to the web service. If I am sending lots of smaller chunks to the webservice, what does my web service look like?
Would it still have the following signature?

public string receiveData(byte[] data, string label);

Thanks,

- Thomas
Offline  
Old 04-29-2009, 09:05 AM   #13
bibodo
New Member
 
Join Date: Apr 2009
Model: 9500
PIN: N/A
Carrier: Vodafon
Posts: 1
Unhappy

Quote:
Originally Posted by goulamass View Post
All right.

Now it's works.

Thanks for your answer
Hi goulamass,

how did you get it running.
I have a web service implemented as Java class.
When i generate the BlackBerry stub classes with the Sun Java Wireless Toolkit
the generated stub files contains errors where I uses byte[] in the web service Java class. The WSDL I used to generate the stubs mapped the byte[] to hexBinary. And it seems to that hexBinary can not be used on JME applications.
Offline  
Old 06-01-2009, 11:17 AM   #14
alykat
New Member
 
Join Date: May 2009
Model: 9000
PIN: N/A
Carrier: ATT
Posts: 3
Default

The best thing to do is probably just specify the parameter as a String. Base64 is ASCII representation of binary data.
Offline  
Old 11-10-2009, 10:27 AM   #15
bhargav
New Member
 
Join Date: Oct 2009
Model: 8300
PIN: N/A
Carrier: adad
Posts: 2
Default

Could you please describe your solution.
I am also working on the same thing.
I stored an image in to a byte array. then encoding it to string using Base64.encode(byte [] array). passing the encoded string as parameter to the web service.
At the client I am decoding the string to get byte array. After that I am constructing the image from byte array and storing it in the server.

But there seems to be some problem.

Please find the service and client code here

This is my web service method:

public String UploadFile(String image,String location,String fileName)
{
File file = new File(location+fileName);
byte [] ary = Base64.decode(image);
try
{
FileOutputStream fOut = new FileOutputStream(file);
fOut.write(ary);
fOut.flush();
fOut.close();
}
catch (FileNotFoundException e)
{
return e.getMessage();
}
catch (IOException e)
{
return e.getMessage();
}
catch(Exception ex)
{
return ex.getMessage();
}
return "Success";
}

The client code is :

{
Object response = null;
String URL = "End point URL";
String method = "UploadFile";
String NameSpace = "namespace";
FileConnection fc = null;
byte [] ary = null;
try
{
fc = (FileConnection)Connector.open("file:///store/home/user/pictures/IMG00010.jpg",Connector.READ_WRITE);
int size = (int) fc.fileSize();
ary = new byte[size];
fc.openDataInputStream().read(ary);
fc.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}

SoapObject client = new SoapObject(NameSpace,method);
client.addProperty("image",new SoapPrimitive(SoapEnvelope.ENC,"base64",Base64.enc ode(ary)));
client.addProperty("location","Test/");
client.addProperty("fileFame",EnterName.getString( ));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = client;
HttpTransport http = new HttpTransport(URL);
try
{
http.call(method,envelope);
}
catch(InterruptedIOException io)
{
io.printStackTrace();
}
catch (IOException e)
{
System.err.println(e);
}
catch (XmlPullParserException e)
{
System.err.println(e);

}
catch(OutOfMemoryError e)
{
System.out.println(e.getMessage());
}
catch(Exception e)
{
e.printStackTrace();
}

try
{
response = envelope.getResponse();
Alert greet = new Alert(response.toString());
display.setCurrent(greet);

}
catch (SoapFault e)
{
System.err.println(e);
System.out.println("Soap Fault");
}
catch(NullPointerException ne)
{
System.err.println(ne);
}
}


Any problem with the above code??
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


1pcs New YUKEN Solenoid Valve DSG-03-3C4-A220-50 picture

1pcs New YUKEN Solenoid Valve DSG-03-3C4-A220-50

$85.38



1pcs New CKD Solenoid Valve 4KB240-08-L-AC110V picture

1pcs New CKD Solenoid Valve 4KB240-08-L-AC110V

$167.00



1pcs New CKD Solenoid Valve F3000-8-W-F picture

1pcs New CKD Solenoid Valve F3000-8-W-F

$35.00



1pcs New CKD Solenoid Valve RP2000-10-08 picture

1pcs New CKD Solenoid Valve RP2000-10-08

$92.55



Winch Solenoid Relay Control Contactor Box for 8000-17000Lbs Electric ATV UTV Wi picture

Winch Solenoid Relay Control Contactor Box for 8000-17000Lbs Electric ATV UTV Wi

$86.52



Cole Hersee (24059-BP) 12V Insulated SPST Continuous Duty Solenoid picture

Cole Hersee (24059-BP) 12V Insulated SPST Continuous Duty Solenoid

$29.55







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.