Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
PeteBarkley
Posts: 19
Registered: ‎07-14-2008
My Device: Not Specified

Connecting to .asmx .net server and writing data

Hi, i am trying to write data to a web service as follows:

 

HttpConnection hConn = null; OutputStream outS = null; hConn = (HttpConnection) (Connector.open("http://something.com:8080/BBwebservice/BBTracker.asmx?op=ReportInfo")); hConn.setRequestMethod(HttpConnection.POST); outS = hConn.openOutputStream(); outS.write(data.getBytes()); start = false; sending = false; outS.flush(); int responseCode = hConn.getResponseCode(); res2 = hConn.getResponseMessage(); if (responseCode == HttpConnection.HTTP_OK) sendResult = true; else sendResult = false;

 

 

The webservice "ReportInfo" method is supposed to recieve the data written and then save it to a data base. But it is not working

 

Any help is appreciated.

Please use plain text.
Developer
ryandevore
Posts: 46
Registered: ‎07-12-2008
My Device: Not Specified

Re: Connecting to .asmx .net server and writing data

Not sure if this will help, but I'm connecting to a .NET web service just using the raw Http/Https Connection objects in java.  In my code, I'm setting a few properties on the HttpsConnection object prior to writing data in the post.

 

In addition to setting the POST request method, I also make the following calls

httpConnection.setRequestProperty("Content-Type", "text/xml"); httpConnection.setRequestProperty("Content-Length", String.valueOf(sendBuffer.length)); // sendBuffer are the bytes to be written httpConnection.setRequestProperty("SOAPAction", {Soap namespace + Soap method here}); httpConnection.setRequestProperty("User-Agent", {User Agent String here});

If you are not using a SOAP web service then you can probably ignore that one.  And I'm not sure if the user-agent is truly needed.

Please use plain text.
New Developer
PeteBarkley
Posts: 19
Registered: ‎07-14-2008
My Device: Not Specified

Re: Connecting to .asmx .net server and writing data

[ Edited ]
 

HttpConnection hConn = null; OutputStream outS = null; hConn = (HttpConnection) (Connector.open("http://mywebservice.com:8080/BBwebservice/BBTracker.asmx?op=ReportInfo"));

String login = "123456789:Password"; byte[] encoded = Base64OutputStream.encode(login.getBytes(), 0, login.length(), false, false); hConn.setRequestProperty("Authorization", "Basic " + new String(encoded)); hConn.setRequestProperty("Content-Type", "text/xml"); hConn.setRequestProperty("Content-Length", String.valueOf(data.length())); hConn.setRequestProperty("SOAPAction", "ReportInfo"); hConn.setRequestMethod(HttpConnection.POST); outS = hConn.openOutputStream(); outS.write(data.getBytes()); start = false; sending = false; outS.flush(); int responseCode = hConn.getResponseCode(); res2 = hConn.getResponseMessage(); if (responseCode == HttpConnection.HTTP_OK) sendResult = true; else sendResult = false;

Thanks Ryan, 

 

Updated my code to that, getting an "Proxy Authentication Error" in the response message. also do i need to inclunde the op=ReportInfo in the URL?

 

Any suggestions?

Message Edited by PeteBarkley on 08-08-2008 12:05 PM
Message Edited by PeteBarkley on 08-08-2008 12:05 PM
Please use plain text.
New Developer
PeteBarkley
Posts: 19
Registered: ‎07-14-2008
My Device: Not Specified

Re: Connecting to .asmx .net server and writing data

Bump?
Please use plain text.
Developer
kzettel
Posts: 120
Registered: ‎07-16-2008
My Device: 9000

Re: Connecting to .asmx .net server and writing data

It sounds like a problem on the server side.  How is your web service security configured?  Is it setup for Basic Auth or one of Microsoft's "better" versions of it?  You may also want to check to see if there is any error in your server's event logs which may indicate why your web service is rejecting the request.  Which http response code are you getting?

Kurt Zettel | Chief Architect | Metova
www.metova.com
Please use plain text.