06-10-2011 02:59 PM - edited 06-10-2011 04:15 PM
I am writing my first application for Blackberry (or any mobile device for that matter) and I'm having a problem making an http request from a Blackberry simulator to a WCF service running locally. I am using the Blackberry Eclipse plug-in, so when I run the application it first launches the MDS-CS simulator and then launches the Blackberry simulator. In the Blackberry simulator, I can open the Blackberry browser and send a request to the WCF service running on my machine with no problems. The service receives the request and inserts a record in the database. However, when the MIDlet application attempts to send the same http request to the WCF service, I get an http 400 response code with a "Bad Request" response message. Here is the code I'm using to send the request:
// Make call to WCF service System.out.println("Making call to WCF service."); connection = (HttpConnection) Connector.open("http://<my_ip_address>/MyService/M
yService.svc/ajax/ServiceMethod?Parameter1=1&Param eter2=2&Parameter3=3&Parameter4=4;deviceside=false "); connection.setRequestMethod(HttpConnection.GET); rc = connection.getResponseCode(); System.out.println("rc="+rc+";response message="+connection.getResponseMessage()); connection.close();
You'll notice that at the end of my URL I have ";deviceside=false. I read somewhere that you would include that if you're using MDS; not sure if that's right though. I've tried it with and without that at the end but I get the same response. I've been doing quite a bit of Googling and poking around on the Blackberry website but I have not had any luck yet.
Any ideas as to what could be the problem? Are there any changes to the rimpublic.property file that I need to make? Or any other request properties I need to set on the HttpConnection object?
Thanks in advance.
EDIT: I changed the url in the MIDlet application to http://www.google.com and I got a response of 200/OK.
Solved! Go to Solution.
06-10-2011 06:25 PM
I created a basic .NET web app and made a call from the Blackberry MIDlet app to an .aspx page within the app and I got a response of 200/OK. I think the original problem has to do with the WCF service. I'll take a look and post a question on a .NET forum if I have to. If I'm able to get a solution I'll post it here as a reply.
06-12-2011 02:39 PM
I ended up creating a RESTful WCF service from scratch using this tutorial and it worked. I can call it from the browser and from the MIDlet app successfully. I suppose the original WCF service I was calling is not fully RESTful. The way it's configured is much different from what's in the tutorial so I'll have to take a closer look.