BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-01-2009, 07:48 PM   #1 (permalink)
New Member
 
Join Date: Feb 2009
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default $25.00 for someone to show me how to connect to a .NET web service

Please Login to Remove!

I need to connect to an asp.net web service from a black berry app. I have tried KSOAP but I can't get it to work. I keep getting verification errors when I try to attach through the debugger. I am willing to pay to have someone write some quick code with directions to do this. Please help.
Offline  
Old 03-01-2009, 08:16 PM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have tried connecting to a .net webservice using ksoap2 and jsr172. send me a private message on what exactly it is you want. maybe i can help.
Offline  
Old 03-01-2009, 10:40 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2007
Location: Ernakulam, Kerala, India
Model: 8320
Carrier: Airtel
Posts: 65
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Connect with .Net Web Service from BB

Hi Steve
I think you can use the raw HTTP connection for the purpose, or maybe if you know how to create a stub from WSDL, then its a more feasible option.

To create stub, you need to download sun's wireless toolkit, there you wil
find an option to generate the stub. Then you can directly use it to communicate with .net web service.
__________________
Regards
Anand.
Offline  
Old 03-03-2009, 03:50 PM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: May 2008
Model: 8700
PIN: N/A
Carrier: Telcel
Posts: 69
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'll send you later my paypal account so you can deposit there my 25 dlls. Better yet, buy me a couple of psn card and send me the codes over a private message. That'd work better

I have been working with KSOAP2 and BB for quite a while, and they wokr perfectly, here is what you need

You only need this 3 imports to work well

Code:
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.HttpTransport;
And you'll be having this variables

Code:
    private SoapObject table = null;							// Its the table of a DataSet
    private SoapObject client = null;							// Its the client pettition to the web service
    private SoapObject tableRow = null;						// Gets the information of a row from the table DataSet
    private SoapObject responseBody = null;					// Its the whole response of the WebService
    private HttpTransport transport = null;					// Its whta is used to make the call to the WebService
    private SoapSerializationEnvelope sse = null;				// Contains the information of the request and the response of the webservice
Now, i'll put how things work for 2 cases. 1, when asking for a DataSet with multiple tables and multiples rows each table. 2, when asking for a single response, like a integer or a boolean response

Lets firts start up our webServices our variables

Code:
sse = new SoapSerializationEnvelope(SoapEnvelope.VER11); // SOAP version is indicated here. Version 11 works nice
sse.addMapping(<WebService NameSpace>, <Name of the Class using it>, this.getClass());
sse.dotNet = true; // We stablish we sill be working with .NET webservices
transport = new HttpTransport(<URL of the webservices>);
transport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");	
transporte.debug = debug; // Set it to either use transport.dumpRequest or dumpReponse to see the xml of the webservice request of response
Now, lets see the example of requesting the information and the webservices gives us a DataSet with 2 tables

Code:
// Here we set who are we gonna call, give the method arguments and do the call
client = new SoapObject(<WebServiceNameSpace>, <WebService Method Name we want to reuqest>);
// You can add as many properties as many as you need. I'd say that you set your webservices method to recieve only strings and do the convertions on you webservice. Its quite hard work with primitive values
client.addProperty(<agument name as String>, <argument Value>);
sse.setOutputSoapObject(client);
sse.bodyOut = client;
transporte.call(<WebService direct url>, sse);
Once we did the call for the WebService, we'll work on the reponse of this one

Code:
// We'll get the whole XML reponse with all the information
responseBody = (SoapObject) sse.getResponse();
// Now, the reponse works as a Vector. On position 0 we have the information of the Reponse while in position 1 we get the info we requested. So we get rid of the information reponse and lets grab the info we requested
responseBody = (SoapObject) responseBody.getProperty(1);
// And now, we have the n tables the WebService returned to us with the information, but still we can't access the info, so we'll get one of the tables separated. We'll use a very different variable for not to lose the whole info the webservice sended us. Once again, the tables are contained on a Vector. Lets grab the first one
table = (SoapObject) responseBody.getProperty(0);
// Now we have the table, but still can't use the info, soooo, lets grab a row individually
tableRow = (SoapObject) table.getProperty(0);
And there you have it, you can now access to the info of the table. How so? easy, just like this

Code:
tableRow.getProperty(<ColumnName>).toString()
Easy right, that's it for grabing the info of a DataSet with one or more tables. Now, lets see how single responses work, like integers or booleans, the only thing, different from the example before, you'll need to do, is, instead of saving the SoapSerializationEnvelope reponse on a SoapObject, juts grab the SSE reponse like this

Code:
sse.getResponse()
If i want to check that a WebService returned me a "true" when this one return boolean values, i do this

Code:
sse.getResponse().toString().equals("true")
Yeah, i convert the response to string, easy to handle and convert to other types.

Its not much of a hassle to work with KSOAP2, i have found it easy to work with and pretty clean. Of course, JSR172 is cleaner and easier, but i coulnd't bring myself to make JSR-172 to work on several BB and decided to use this.

Hope this minitut worked, any question just post them here, and i'll be waiting for my PSN card codes.

Just as a last note, this is the library i'm using of KSOAP2
ksoap2-j2me-core-2.1.2.jar

And i have been developing on Java ME Platform SDK 3.0 Early Access. i'm having some troubles using this library on BlackBerry JDE. Had to make the jump cuz my boss want me to use direct BlackBerry API and not J2ME

Last edited by CJLopez : 03-03-2009 at 03:54 PM.
Offline  
Old 03-03-2009, 09:37 PM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2007
Location: Ernakulam, Kerala, India
Model: 8320
Carrier: Airtel
Posts: 65
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi CJ

Could you tell If How will you incude a soap header property using ksoap ?
The following code will only set the Header not the soap header.

Code:
client.addProperty(<agument name as String>, <argument Value>);
__________________
Regards
Anand.
Offline  
Old 03-04-2009, 09:38 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: May 2008
Model: 8700
PIN: N/A
Carrier: Telcel
Posts: 69
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh, sorry, i don't know how to set the SoapHeader. Yeah, thats only the header of the WebMethod, but for the whole WebService, i didn't bothered with that so I don't know how to set it. Maybe you can find something on the API of the library, must be withing the SoapSerializationEnevelope where you might want to look, as there is where the information to be established for communication with the SOAP service is set.

KSoap 2 API

I think it is set with default values. You should look into the method writeHeader, it uses a XMLWriter as a parameter, maybe you can add the headers there, not sure how its used, never bothered looking on them
Offline  
Old 03-06-2009, 02:51 AM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2007
Location: Ernakulam, Kerala, India
Model: 8320
Carrier: Airtel
Posts: 65
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default How to set Soap Header with Ksoap2

Hi CJ,

I guess it will work, But now I am using the raw Post method, so that I can handle these things much easier, and avoid any unwanted stuff.

Anyway thanks for the info, I guess this info will help somone else.
__________________
Regards
Anand.
Offline  
Old 03-06-2009, 06:43 PM   #8 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2008
Model: Pearl
PIN: N/A
Carrier: T-Mobile
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by CJLopez View Post
Code:
sse = new SoapSerializationEnvelope(SoapEnvelope.VER11); // SOAP version is indicated here. Version 11 works nice
sse.addMapping(<WebService NameSpace>, <Name of the Class using it>, this.getClass());
sse.dotNet = true; // We stablish we sill be working with .NET webservices
transport = new HttpTransport(<URL of the webservices>);
transport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");	
transporte.debug = debug; // Set it to either use transport.dumpRequest or dumpReponse to see the xml of the webservice request of response
Hey CJ, what exactly needs to get fed into the sse.addMapping() call?

I understand the webservice namespace, but what's the "name of the class using it"?
Offline  
Old 03-10-2009, 03:34 PM   #9 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2008
Model: Pearl
PIN: N/A
Carrier: T-Mobile
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can anyone answer my question in the previous post please?
Offline  
Old 03-11-2009, 02:56 PM   #10 (permalink)
Thumbs Must Hurt
 
Join Date: May 2008
Model: 8700
PIN: N/A
Carrier: Telcel
Posts: 69
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

<WebService NameSpace>.- If you write you webservice url and after the termination ".asmx" you add ?WSDL, it will give you the WSDL of you webservices, for example

http://youhost/webservice/webservice.asmx?WSDL

There is a tag named targetNamespace=<WebService NameSpace>

Note: This is for ASP.Net webservices, i ingore how it used by PHP or Java WebServices

<Name of the Class using it>.- Its the name of the class under which you are using the WS

Code:
class MyApplication
{
    .
    .
    .
    .
    void MyMethod()
    {
        .
        .
        .
        sse.addMapping(<WebService NameSpace>, "MyApplication", this.getClass());
        .
        .
        .
    }
    .
    .
    .
    .
}
this.getClass().- You are just getting the reference to the class on which the SoapSerializationEnvelope is being used

here is the API of the code
Offline  
Old 03-17-2009, 08:27 PM   #11 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2008
Model: Pearl
PIN: N/A
Carrier: T-Mobile
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for clarifying. I used those variables, yet I still get everything cast as anyType when it comes back. I know ksoap wants me to define the objects so that it can hydrate them, but I'm kind of lost on how to do that exactly.
Offline  
Old 06-21-2009, 10:22 AM   #12 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2009
Location: CANADA
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 64
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
here is some other opinion about addMapping() second parameter:
Dr. Dobb's | SOAP-enabling Mobile Devices with KSOAP-2 | June 23, 2008
Looks quite different.
Next, I think both lines do the same,
PHP Code:
sse.setOutputSoapObject(client);
sse.bodyOut client
so we can get rid of one of them.
And I have suspicison that in some cases the line:
PHP Code:
responseBody = (SoapObject)responseBody.getProperty(1); 
may cause ClassCastException

Last edited by koic : 06-21-2009 at 10:42 AM.
Offline  
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





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