BlackBerry Forums Support Community

Closed Thread
LinkBack Thread Tools
Old 10-01-2010, 03:38 AM   #1 (permalink)
New Member
Join Date: Oct 2010
Model: 9500
Carrier: Airtel
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem posting data to WCF/Rest from blackberry application

Please Login to Remove!


I am trying to Post data from my Blackberry application through HttpConnection to WFC/REST service. The data is in XML format.
Can someone please give me a solution to post data to WCF ? Are there any specific configuration settings that need to be set for BlackBerry?

It is working perfectly when Iím running from J2ME WTK emulator but the same application when I run on Blackberry Emulator, the server throwing an error.

[ The server encountered an error processing the request. The exception message is 'The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.'. See server logs for more details. The exception stack trace is:</P>
<P class="intro"> at System.ServiceModel.Dispatcher.DemultiplexingDispa tchMessageFormatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.UriTemplateDispatch Formatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.CompositeDispatchFo rmatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.DispatchOperationRu ntime.DeserializeInputs(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.DispatchOperationRu ntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process( Boolean isOperationContextSet)

Here is my code for HttpConnection :

private void configureConncetion(HttpConnection conn) throws IOException {

		//conn.setRequestProperty("User-Agent", ua);
		String locale = System.getProperty("microedition.locale");
		if (locale == null) { locale = "en-US";	}
		conn.setRequestProperty("Accept-Language", locale);
		conn.setRequestProperty("Content-Type", "text /xml");

public HttpConnection getConnection(String url, int access) throws IOException {
		HttpConnection conn = (HttpConnection), access);
		return conn;

public String post(String url, String data) throws IOException {

		HttpConnection hcon = null;
		DataInputStream dis = null;
		DataOutputStream dos = null;
		StringBuffer responseMessage = new StringBuffer();
		try {
			int redirectTimes = 0;
			boolean redirect;
			do {
				redirect = false;
				// an HttpConnection with both read and write access
				hcon = getConnection(url, Connector.READ_WRITE);
				// set the request method to POST
				// overwrite content type to be form based
				//hcon.setRequestProperty("Content-Type", "text/xml");
				// set message length
				if (data != null) {
					hcon.setRequestProperty("Content-Length", ""
							+ data.length());

				if (data != null) {
					// obtain DataOutputStream for sending the request string
					dos = hcon.openDataOutputStream();
					byte[] request_body = data.getBytes();
					// send request string to server
					for (int i = 0; i < request_body.length; i++) {
					}// end for( int i = 0; i < request_body.length; i++ )
					dos.flush(); // Including this line may produce
					// undesiredresults on certain devices

				// obtain DataInputStream for receiving server response
				dis = new DataInputStream(hcon.openInputStream());
				// retrieve the response from server
				int ch;
				while ((ch = != -1) {
					responseMessage.append((char) ch);
				}// end while( ( ch = ) != -1 ) {
				// check status code
				int status = hcon.getResponseCode();
                                		switch (status) {
				case HttpConnection.HTTP_OK: // Success!
				case HttpConnection.HTTP_TEMP_REDIRECT:
				case HttpConnection.HTTP_MOVED_TEMP:
				case HttpConnection.HTTP_MOVED_PERM:
					// Redirect: get the new location
					url = hcon.getHeaderField("location");
					System.out.println("Redirect: " + url);

					if (dis != null) dis.close();
					if (hcon != null) hcon.close();
					hcon = null;
					redirect = true;
					// Error: throw exception
					throw new IOException("Response status not OK:" + status);

				// max 5 redirects
			} while (redirect == true && redirectTimes < 5);

			if (redirectTimes == 5) {
				throw new IOException("Too much redirects");
		} catch (Exception e) {
                          VLogFile.writeLog("Entered REST Exception"+e.getMessage());
		} finally {
			// free up i/o streams and http connection
			try {
				if (hcon != null) hcon.close();
				if (dis != null) dis.close();
				if (dos != null) dos.close();
			} catch (IOException ioe) {
			}// end try/catch
		}// end try/catch/finally
		return responseMessage.toString();
Closed Thread

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

MSA Altair 4x Multi Gas Confined Detector O2 CO H2S LEL w/Charger
MSA Altair 4x Multi Gas Confined Detector O2 CO H2S LEL w/Charger pictureMSA Altair H2S Single Gas Detector (11 Months Remaining)
MSA Altair H2S Single Gas Detector (11 Months Remaining) pictureLot of 2 MSA Altair 4X Multi Gas Meter Monitor Detector, Need Calibrated
Lot of 2 MSA Altair 4X Multi Gas Meter Monitor Detector, Need Calibrated  pictureMSA 10107602 ALTAIR 4X Gas Detector, Charcoal, LEL, O2, CO, H2S
MSA 10107602 ALTAIR 4X Gas Detector, Charcoal, LEL, O2, CO, H2S pictureNew MSA Altair 4X Mining Multi-Gas Detector
New MSA Altair 4X Mining Multi-Gas Detector   picture

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