I am developing an application to use httpconnection to get some data to a .Net Webservice. The code is working fine when i host the webservice locally and test it with Eclipse simulator, but when i host the webservice on the public deployment server and package the Blackberry app to my device all am getting is is a respose code 500. Please can someone give me a clue, an answer or a solution to what migth be causing this?
Below are the code i used:
String URL = WebServiceURL+"/Login"+getConnectionParameter();
public static String getConnectionParameter() {
String ConnectionParameter ="" ;
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
// Connected to a WiFi access point
ConnectionParameter = ";interface=wifi";
} else {
int coverageStatus = CoverageInfo.getCoverageStatus();
ServiceRecord record = getWAP2ServiceRecord();
if (record != null && (coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage and a WAP 2.0 service book record
ConnectionParameter = ";deviceside=true;ConnectionUID="+ record.getUid();
} else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {
// Have an MDS service book and network coverage
ConnectionParameter = ";deviceside=false";
} else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage but no WAP 2.0 service book record
ConnectionParameter = ";deviceside=true";
}
}
return ConnectionParameter;
}
URLEncodedPostData oPostData = new URLEncodedPostData(
URLEncodedPostData.DEFAULT_CHARSET, false);
oPostData.append("username",username.getText());
oPostData.append("compressedpicture",HomeScreen.convertByteArrayToString(imageArray));
oPostData.append("email",email.getText());
oPostData.append("password",password.getText());
oPostData.append("pin",pin.getText());
oPostData.append("extension",extension);
String URL = MYAPP.WebServiceURL+"/SignUp"+MYAPP.getConnectionParameter();
String result = HomeScreen.postinfo(URL,oPostData);
Dialog.inform(result);
if(result.indexOf("success")!= -1){
Dialog.inform("You Have just sign up. Congratulations.");
}else{
Dialog.inform("There is an issue registering you");
}
public static String postinfo(String _URL,URLEncodedPostData _PostData) {
String result = "";
try {
HttpConnection conn = (HttpConnection) Connector.open(_URL,
Connector.READ_WRITE);
if (_PostData != null) {
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length",
Integer.toString(_PostData.size()));
OutputStream strmOut = conn.openOutputStream();
strmOut.write(_PostData.getBytes());
strmOut.close();
} else {
conn.setRequestMethod(HttpConnection.GET);
}
int responseCode = conn.getResponseCode();
if (responseCode == HttpConnection.HTTP_OK) {
InputStream data = conn.openInputStream();
StringBuffer raw = new StringBuffer();
byte[] buf = new byte[4096];
int nRead = data.read(buf);
while (nRead > 0) {
raw.append(new String(buf, 0, nRead));
nRead = data.read(buf);
}
result = raw.toString();
//Dialog.alert("Result:" + raw.toString());
//_Dest.updateDestination(raw.toString());
} else {
_Dest.updateDestination("responseCode="
+ Integer.toString(responseCode));
result = "responseCode= "+ Integer.toString(responseCode);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
//_Dest.updateDestination("Exception:" + e.toString());
result = "Exception:" + e.toString();
}
return result;
}
Thanks for all your suggestion Guys. I appreciate them all. I discovered my production server was throwing the internal server error 500 because of of the /WebserviceMethod at end of my URL e.g.
String URL = WebServiceURL+"**/Login**"+getConnectionParameter();
I found a solution using KSOAP2. It worked perfectly well. Though u might av to write some lines of code to handle the parsed response format(KSOAP2 return a parsed format of the response XML).
Am sure you will find the article at this link useful: KSoap Android Web Service Tutorial With Sample Code
It applies to most J2ME based mobile platform.
Once again Thank you all for your time and help.