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 Contributor
Posts: 9
Registered: ‎03-08-2010
My Device: Curve 8320, Bold 9000
My Carrier: Telefonica

Calling a web service from JDE development

Hello, everybody.

 

I'm begginer in Java development for Blackberry, and Im working with JDE and its amazing!

 

I'm a Visual Studio developer, but for develop to Blackberry, Java is the best!. Blackberry with VisualStudio does not solvel all the needs (IMHO).

 

Actually, I need to call a simple web service from a blacbkerry app. A .NET web service on a remote Microsoft IIS, that returns data. I dont know how to add a reference in my JDE project or how to call it and how to get the returned data.

 

Please, can you help me?

I read some documents related with web service, but I dont get it yet.

 

This is the environment that I'm using:

--------------------------------------------------------------------------------------------------

Windows 7 Ultimate, 32bits at home, 64bits at work.

JDE 4.2.1

Blackberry 8800 Simulator with OS 4.2.1

--------------------------------------------------------------------------------------------------

 

Regards,


Gustavo Barboza

 

Developer
Posts: 159
Registered: ‎08-19-2008
My Device: Not Specified

Re: Calling a web service from JDE development

You need to make http connection to your web service by calling its url ,then u can parse the xml content return by web service

 

Go through this article of how to make httpconnection ............

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

 

I think you will try to make http connection via TCP/IP or WAP for testing on simulator must run your MDS ............

 

 

Developer
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: Calling a web service from JDE development

My friend, good luck. I've been battling with .NET (C#) web services for hte past 3 weeks. That is not to say that it's impossible -- I've made successful calls to web services using the kSOAP2 library -- but it is most certainly frustrating. I'll give you a few links to get you in the right direction:

 

Craig A Green - BlackBerry and .NET Web Services

Packaging Multiple COD files (external Library)

 

I would suggest using kSOAP2 to build your SOAP request. A link to the preverified library is in the first link above. Here's some sample code for call a .net web service:

 

 

    try
    {
      SoapObject s = new SoapObject (namespace, methodName);
      s.newInstance ();
      s.addProperty ("a", "5");
      s.addProperty ("b", "6");
      
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope 
                                           (SoapEnvelope.VER11);
      envelope.bodyOut = s;
      envelope.dotNet = true;
      envelope.implicitTypes = true;
      envelope.encodingStyle = "utf-8";
      envelope.enc = SoapSerializationEnvelope.ENC2001;
      envelope.xsd = SoapEnvelope.XSD;
      envelope.xsi = SoapEnvelope.XSI;
      
      //Build connection
      HttpTransport transport = new HttpTransport
                                (IP + qualifiedPath);
      
      //Initiate Connection
      String response;
      
      try 
      {
        transport.debug = true;
        
        transport.call (namespace + methodName, envelope);
        
        response = envelope.getResponse ().toString ();
        
        System.out.println (transport.responseDump);
        System.out.println (transport.requestDump);
        
        //bodyIn contains the response. envelope.toString () returns
        //a nicely formatted String to quickly check parameters
        System.out.println (envelope.bodyIn);
      }
      catch (Exception e)
      {
        System.out.println (e);
      }
    }
    catch (Exception e)
    {
      System.out.println (e);
    }

 

 

Good luck, and hope that helps,

~Dom

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
Developer
Posts: 159
Registered: ‎08-19-2008
My Device: Not Specified

Re: Calling a web service from JDE development

Hi Dom,

               You can generate  stub files by using sun java wireless tool kit 2.5 of JSR 172 & then u can use thos stub files to make a call to your .Net Web Service...............Using KSOAP library for .Net Web also can be done but for that u need to change your Web Service Profile

 

 

For JSR -172 you can use this articale

 

 http://jnb.ociweb.com/jnb/jnbApr2005.html

 

For  KSOAP2  library

you can use this article

 

http://www.discussweb.com/java-programming/1731-call-net-web-service-j2me.html

 

i generally make httpConnection to my .Net web service and then parse XML ,i know it is not generic way of calling web service

 

For generic you can go through above articles.................i have tried those & it works............

New Contributor
Posts: 9
Registered: ‎03-08-2010
My Device: Curve 8320, Bold 9000
My Carrier: Telefonica

Re: Calling a web service from JDE development

Hello, everybody. Thanks for your help. I will read and try your opinions, but:

 

1. Can I to call a .Net webservice, and parse the returned data, without a library (JSR, KSOAP2, etc.)? Only with my actually environment JDE?

 

2. About: "For generic you can go through above articles.................i have tried those & it works............". What articles you say, please? Where I'll find its?

 

Thanks.

 

Gustavo Barboza

 

 

Developer
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: Calling a web service from JDE development

1. I really don't think so. I've tried many different approaches, and short of writing your own request from scratch (which my more experienced counterparts inform me is not that easy) it doesn't seem possible.

 

2. We both posted two links to helpful articles, all of which were above that particular line. He could be referring to any/all of these.

 

3. @ankit2grover: I've made proper calls to C# web services using kSOAP2. It's not so much a matter of encoding, as there's a flag in the envelope (dotnet) which accounts for the origin language. The issues I've been having are varied, the most recent of which has nothing at all to do with the package itself. See the topic below for more details regarding my specific difficulties:

 

http://supportforums.blackberry.com/t5/Java-Development/Web-service-different-results-based-on-locat...

 

The seasoned programmers at my company have assured me that the packets are correct when they are sent. They just get stripped of their values on arrival. Weird...

 

 


 

 

Anyway, hope that helps,

~Dom

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
Developer
Posts: 159
Registered: ‎08-19-2008
My Device: Not Specified

Re: Calling a web service from JDE development

Yes ,

 1)        You can call your .Net Web service without any KSOAP2 or JSR 182 library ..........make http connection to your web service & call web service method through URL , in return you will get XML and then you can parse XML to retreive your content.

 

2)     I mean you can go to those links i have mentioned .

 

For JSR -172 you can use this articale

 

 http://jnb.ociweb.com/jnb/jnbApr2005.html

 

For  KSOAP2  library

you can use this article

 

http://www.discussweb.com/java-programming/1731-call-net-web-service-j2me.html

 

 

 

  LocationData("http://staging.indegene.com/novartis_oms/User_Manager.asmx/Get_MasterDets?ptblName=designation");

public void LocationData(String URL)
        {
         if(CoverageInfo.getCoverageStatus()== CoverageInfo.COVERAGE_NONE)
           {
               Dialog.alert("No Internet Connection");
           }
           else
           {
                    HttpConnection httpConnector = null;
                    InputStream in = null;
                    byte[] bufferLectura;
                    int inChar;
                try 
                    {
                        httpConnector = (HttpConnection)Connector.open(replace(URL," ","%20"),Connector.READ_WRITE);
                        httpConnector.setRequestMethod(HttpConnection.GET) ;
                        in = httpConnector.openInputStream();
                        long longitudDatos = httpConnector.getLength();
                        byte[] data = new byte[in.available()];
                                                    int len = 0;
                                                    int size = 0;
                                                    StringBuffer raw = new StringBuffer();
                                                    while ( -1 != (len = in.read(data)) )
                                                    {
                                                        raw.append(new String(data, 0, len));
                                                        size += len;
                                                    }
                                                String content = raw.toString().trim();
                                              //  System.out.println(content);
                                           
                                                        
                                                        uiApp.Desg.removeAllElements();
                                                        MySplitName(content,"</DesigID>","<DesigID>");
             public void MySplitName(String parse,String delimeter,String name)
    {
        int npos = 0;
        int fpos =0;
        String value = "";
        while(parse.indexOf(delimeter,npos)>0)
            {
                fpos =parse.indexOf(name,fpos)+delimeter.length()-1;
                npos = parse.indexOf(delimeter,npos) + delimeter.length();
                value  = parse.substring(fpos,npos-delimeter.length());
           
            if(name =="<DesigID>")
              uiApp.DesId.addElement(value);
             
                                                         
 }

  public String replace(final String aInput,final String aOldPattern,final String aNewPattern)
    {
    
        final StringBuffer result = new StringBuffer();
        int startIdx = 0;
        int idxOld = 0;
        while ((idxOld = aInput.indexOf(aOldPattern, startIdx)) >= 0) 
        {
            result.append(aInput.substring(startIdx, idxOld));
            result.append(aNewPattern);
            startIdx = idxOld + aOldPattern.length();
        }
        result.append(aInput.substring(startIdx));
        return result.toString();
    }

 

 

You can use above code for fetching content from  .net web service. I use this code to call .net web servie in which i make http connection using LocationData method .............. & then i parse the return xml content using Mysplitname   function ...............here DesID is a vector & uiApp is a object of my application.

 

This code may give u compilation error............It is just for giving a hint to you how to do it...............

 

4) @Dom , i go through your issue & see whether i can connect to web service using KSOAP2 library or not ........i will reply you on this thread.............

 

Highlighted
New Contributor
Posts: 9
Registered: ‎03-08-2010
My Device: Curve 8320, Bold 9000
My Carrier: Telefonica

Re: Calling a web service from JDE development

Thanks, ankit2grover and Dom, for your promptly and great help.

I will do some test about your information, and I'll return you the results.

 

Best regards.

 

Gustavo Adolfo