Forum Stats

  • 3,875,873 Users
  • 2,266,977 Discussions


How to connect to a Web Service?

843851 Member Posts: 19,484
edited Jul 16, 2010 10:11AM in Java ME SDK

I have to connect to a Web Service from my J2ME application. I was thinking that, we can retrieve data from a Web Service using Httpconnection and streams. But I couldn't do like that. Then I came to know that, by using stub generator we can retrive the data in xml format if we locate WSDL file of that web service (JSR 172). So, in stub generator, I located the WSDL file, output path and gave output package name. But it's showing

{color:#800000}Stub Generation failed
error:modeler error:model error:invalid entity name:"schema" (in namespace: "")
The web service is created using .NET and can anyone help me in this issue? (I'm using WTK 2.5.2). If i can generate the stub classes using this WSDL file, it will be highly beneficial. Otherwise, is there any other way to connect a MIDlet to a Web Service and retrieve data?


  • 843851
    843851 Member Posts: 19,484
    Hi, could you find a way for retrieve data for web service? I am using httpconnection but my data in json are lossing by some rason.Regards
  • 843851
    843851 Member Posts: 19,484
    I just used HttpConnection to connect to the webservice and I'm getting the response in XML format.
  • 843851
    843851 Member Posts: 19,484
    Thanks for your reply. ok, but your xml response is heavyweight? I have a lot of data for retrieve of server. Can you put your code for get data of server with httpconnection? thanks and regards
  • 805890
    805890 Member Posts: 12

    Your exception says quite a lot. Is your schema identified as: Try using instead.

  • 843851
    843851 Member Posts: 19,484

    I used the following code
                conn = (HttpConnection);
                conn.setRequestProperty("Connection", "Keep-Alive");
                int rc = ((HttpConnection)conn).getResponseCode();
                if(rc != HttpConnection.HTTP_OK) throw new IOException("HTTP response code"+rc);
                is = conn.openDataInputStream();
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                doc = db.parse(is);
    if doc is not null, we can parse the contents and use it. I didn't have too much of data. The above code is working fine for me.
This discussion has been closed.