5 Replies Latest reply: Jul 16, 2010 7:02 AM by 805890 RSS

    How to connect to a Web Service?


      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: "http://www.w3.org/2001/XMLSchema")
      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?
        • 1. Re: How to connect to a Web Service?
          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
          • 2. Re: How to connect to a Web Service?
            I just used HttpConnection to connect to the webservice and I'm getting the response in XML format.
            • 3. Re: How to connect to a Web Service?
              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
              • 4. Re: How to connect to a Web Service?

                Your exception says quite a lot. Is your schema identified as: http://www.w3.org/2001/XMLSchema? Try using http://www.w3.org/2001/XMLSchema.dtd instead.

                • 5. Re: How to connect to a Web Service?

                  I used the following code
                              conn = (HttpConnection) Connector.open(url);
                              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.